Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endpoint not generated with the right body parameter #192

Closed
JFCote opened this issue May 31, 2018 · 14 comments
Closed

Endpoint not generated with the right body parameter #192

JFCote opened this issue May 31, 2018 · 14 comments

Comments

@JFCote
Copy link
Member

JFCote commented May 31, 2018

Description

I really don't understand this one.

I have an endpoint declared like this:

  /message-calendars/{message-calendar-id}/message-events:
    post:
      tags:
        - Messaging
      summary: Add a message event to the given message calendar
      operationId: addMessageEventToMessageCalendar
      parameters:
        - $ref: "#/parameters/message-calendar-id"
        - in: body
          name: new-message-event
          required: true
          schema:
            $ref: "./definitions.yaml#/definitions/MessageEventCoreWithTimeListEntries"
      responses:
        200:
          description: OK
          schema:
            $ref: "./definitions.yaml#/definitions/GetMessageEventResponse"

The MessageEventCoreWithTimeListEntries is declared like this:

  MessageEventCoreWithTimeListEntries:
    type: object
    description: "Base of a message event with Time List entries"
    allOf:
      - $ref: "#/definitions/MessageEventCore"
      - type: object
        required:
          - timeListEntries
        properties:
          timeListEntries:
            type: array
            items:
              $ref: "#/definitions/TimeListEntry"

Strangely, the endpoint is generated like this:

GetMessageEventResponse addMessageEventToMessageCalendar(Long messageCalendarId, MessageEventCore body) throws Exception;

Instead of:

public GetMessageEventResponse addMessageEventToMessageCalendar(Long messageCalendarId, MessageEventCoreWithTimeListEntries newMessageEvent) throws Exception;

Please note that the MessageEventCoreWithTimeListEntries model is generated, but not used in the declaration of the endpoint...

openapi-generator version

Latest master

Command line used for generation

java -jar openapi-generator-cli.jar generate -i swagger.yaml --generator-name java-play-framework -o generatedServer -DhideGenerationTimestamp=true

Steps to reproduce

Just run the above command

Related issues/PRs

No idea

Suggest a fix/enhancement

No idea!

@JFCote JFCote added this to the 3.0.2 milestone Jun 14, 2018
@JFCote
Copy link
Member Author

JFCote commented Jun 14, 2018

I have tagged this in 3.0.2 because I think this is very blocking and we should not release anything without this fix but feel free to move it to 3.0.3 or later if needed. I just don't want it to be forgotten.

@jmini
Copy link
Member

jmini commented Jun 15, 2018

Thank you for the bug report and the investigation.

This is of course a big issue for you (and for other users using the same pattern). The release 3.0.2 is due next monday. If nobodies provide a PR to fix this, it will move to the next release...

@jmini
Copy link
Member

jmini commented Jun 15, 2018

Here a standalone spec to reproduce the problem:

swagger: "2.0"
info:
  version: "2"
  title: "Test API"
basePath: "/xx2"
consumes:
- "application/json"
produces:
- "application/json"
paths:
  /ping:
    post:
      tags:
        - Messaging
      summary: Add a message event to the given message calendar
      operationId: addMessageEventToMessageCalendar
      parameters:
        - in: body
          name: new-message-event
          required: true
          schema:
            $ref: "#/definitions/MessageEventCoreWithTimeListEntries"
      responses:
        200:
          description: OK
definitions:
  MessageEventCoreWithTimeListEntries:
    type: object
    description: "Base of a message event with Time List entries"
    allOf:
      - $ref: "#/definitions/MessageEventCore"
      - type: object
        required:
          - timeListEntries
        properties:
          timeListEntries:
            type: array
            items:
              $ref: "#/definitions/TimeListEntry"
  MessageEventCore:
    type: object
    properties:
      id:
        type: integer
      message:
        type: string
  TimeListEntry:
    type: object
    properties:
      p1:
        type: string
      p2:
        type: string

The wrong generated code can be seen in:
<generated project>/app/controllers/MessagingApiControllerImp.java

public class MessagingApiControllerImp implements MessagingApiControllerImpInterface {
    @Override
    public void addMessageEventToMessageCalendar(MessageEventCore body) throws Exception {
        //Do your magic!!!
    }

}

@JFCote
Copy link
Member Author

JFCote commented Jun 15, 2018

@jmini Thanks. I understand. I would provide a PR myself my I didn't play a lot with the core, mostly worked on multiple generators.

@jmini
Copy link
Member

jmini commented Jun 20, 2018

@JFCote: Have you the possibility to try the version in my PR #358 ?

I think it solves your problem.

@JFCote
Copy link
Member Author

JFCote commented Jun 20, 2018

@jmini Will try this today and let you know!

@JFCote
Copy link
Member Author

JFCote commented Jun 20, 2018

@jmini Will try in the upcoming days, not sure when. A lot going on right now. Sorry for the delay

@JFCote
Copy link
Member Author

JFCote commented Jun 21, 2018

@jmini I confirm that the changes work! Do you need any other confirmation? I could merge this right now if you want.

@jmini
Copy link
Member

jmini commented Jun 22, 2018

Thank you a lot for the test and review.

I have merged the change. Please test 3.0.3-SNAPSHOT and mark this issue as closed.

@JFCote
Copy link
Member Author

JFCote commented Jun 22, 2018

Confirmer fixed in 3.0.3-SNAPSHOT, closing this issue! Thanks a lot!

@softarts
Copy link

I still sae this in 3.4.0 with python generated code:
RetrieveCustomWordsResponse:
allOf:
- $ref: '#/components/schemas/CommonResponse'
- type: object
properties:
name:
type: string
description: the name
words:
type: array
items:
type: string
description: the desc
the generated class 'RetrieveCustomWordsResponse' doesn't have the property in 'CommonResponse'

@wing328
Copy link
Member

wing328 commented Dec 23, 2018

@softarts Can you please try the latest snapshot version which has better support for allOf? You can find it in the readme.

Also it would be nice if you can share the full (minimal) spec to more easily reproduce the issue?

@softarts
Copy link

just tried 4.0.0 snapshot, it is fixed.@wing328

@wing328
Copy link
Member

wing328 commented Dec 23, 2018

@softarts Thanks for the confirmation. Happy holidays!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants