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

Revamp DefaultCodegenConfig fromRequestBody() #99

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

devplayer0
Copy link
Contributor

This makes the behaviour of fromRequestBody() similar to that of fromParameter() (by replacing most of the existing code with code from fromParameter()) in order to fix a number of issues. Notably this includes a lack of handling for enums, both as references (as can be seen in #95) and inline.

Also:

@devplayer0
Copy link
Contributor Author

Hi @HugoMario, I don't think it's actually a problem. (The correct schema is obtained via getSchemaFromBody() and dataType is set accordingly) Here's a snippet from the generated swift4 code:

/**

 - parameter body: (body) Pet to add to the store 
 - parameter completion: completion handler to receive the data and the error objects
 */
open class func addPet(body: NewPet, completion: @escaping ((_ data: Pet?,_ error: Error?) -> Void)) {
    addPetWithRequestBuilder(body: body).execute { (response, error) -> Void in
        completion(response?.body, error)
    }
}

Here is the corresponding section of the OpenAPI spec:

post:
      description: Creates a new pet in the store.  Duplicates are allowed
      operationId: addPet
      requestBody:
        description: Pet to add to the store
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NewPet'
      responses:
        '200':
          description: pet response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

This makes the behaviour of `fromRequestBody()` similar to that of
`fromParameter()` (by replacing most of the existing code with code
from `fromParameter()`) in order to fix a number of issues. Notably this
includes a lack of handling for enums, both as references (as can be
seen in swagger-api#95) and inline.

Also:
 - Add `postProcessRequestBody()` hook for code generators
 - Fix swagger-api#95
Previously the `dataType` for the binary format would be set to the
default of `Object`.

Also: bring the enum check in `fromRequestBody()` up to date with the
final code from pull swagger-api#98
@HugoMario
Copy link
Contributor

Hey @devplayer0, sorry for this delay, i'm wondering what you mean, if it's a problem or not.

in case you wanna merge this chance, is it possible you update the PR or you think we can close this one?

@jacqueminv
Copy link

Lack of handling for enum in the requestBody is an issue for me too. Is there any plan to merge this PR?

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

Successfully merging this pull request may close these issues.

Incorrect dataType output when using a $ref to an enum as the schema in the requestBody
3 participants