OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
20.63k stars 6.29k forks source link

Does it support example #18671

Open zhucj1028 opened 1 month ago

zhucj1028 commented 1 month ago

Currently, trying various syntax and versions, examples cannot be converted to Asciidoc. Is this a bug? If not, please advise on how to export examples in OpenAPI 3.0 and above versions. I saw that I submitted the relevant issue a long time ago, but did not fix it, is that so? I don't think great tools should be like this.

https://github.com/OpenAPITools/openapi-generator/issues/5710

DLMartin- commented 1 month ago

I ran into this issue today while experimenting with the expressjs generated server. In the generated openapi.yaml file, the POST for /pets is not correct. It currently looks like this:

  /pet:
    post:
      description: ""
      operationId: addPet
      requestBody:
        $ref: '#/components/requestBodies/Pet'

But it should look like this (for JSON):

  /pet:
    post:
      description: ""
      operationId: addPet
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/requestBodies/Pet"

I'm not sure which other paths may be broken, but it was annoying. Is this just an issue with the example PetStore yaml file?

zhucj1028 commented 1 month ago

Need to comply with the OpenAPI specification to

requestBody:
  content:
      application/json:
        schema:

This is my example, but it does not support converting example nodes to asciidoc. I set it up according to the OpenAPI specification, but it is not feasible. I don't know how to configure my yaml file.

/test:
    post:
      summary: summary
      description: description
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/testPOSTReq'
            examples:
              name:
                summary: requestDemo
                value:
                  name: tom
                  type:
                    red: test
                    pom: test2
                    dow:
                      test: test3
                  age: 18
  responses:
    '200':
      description: success
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/testPOSTRes200'
          example:
            name: tom
            type:
              red: test
              pom: test2
              dow:
                test: test3
            age: 18
psylector commented 1 week ago
  post:
    summary: Generate OTP SMS
    operationId: generateOtp
    tags:
      - otpSms
    requestBody:
      required: true
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/GenerateOtpRequest'
          examples:
            KnownParty:
              summary: Known party request
              value:
                objectType: 'knownParty'
                smsCode: 'SOME_SMS_CODE'
                langCode: 'CS'
                operationId: null
                operationName: null
                smsData: { }
                partyId: 1001
            UnknownParty:
              summary: Unknown party request
              value:
                objectType: 'unknownParty'
                smsCode: 'SOME_SMS_CODE'
                langCode: 'CS'
                operationId: null
                operationName: null
                smsData: { }
                phoneNumber: '00420606111222'

... not generating examples to @Schema annotation openapi-generator-maven-plugin - version: 7.4.0