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

[BUG] Null example values generated for enum properties #18622

Closed
5 of 6 tasks
alexrjones opened this issue May 9, 2024 · 0 comments · Fixed by #18623
Closed
5 of 6 tasks

[BUG] Null example values generated for enum properties #18622

alexrjones opened this issue May 9, 2024 · 0 comments · Fixed by #18623

Comments

@alexrjones
Copy link
Contributor

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

If a schema has a property that references an enum schema, the example will generate null values for the schema.

openapi-generator version

7.5.0

OpenAPI declaration file content or url

Input:

definitions:
  myresponse:
    type: object
    additionalProperties: false
    properties:
      x:
        $ref: "#/definitions/myenum"
  myenum:
    type: string
    enum:
      - A
      - B
      - C

Expected output:

components:
  schemas:
    myresponse:
      additionalProperties: false
      example:
        x: A
      properties:
        x:
          $ref: '#/components/schemas/myenum'
      type: object
    myenum:
      enum:
        - A
        - B
        - C
      type: string

Actual output:

components:
  schemas:
    myresponse:
      additionalProperties: false
      example:
        x: null
      properties:
        x:
          $ref: '#/components/schemas/myenum'
      type: object
    myenum:
      enum:
      - A
      - B
      - C
      type: string
Generation Details

openapi-generator-cli generate -i "<input-yaml>" -g openapi-yaml

Steps to reproduce
  1. Run the above generator command with the above input yaml
  2. Observe that the output yaml matches the actual output yaml shown above
Related issues/PRs

None that I could find

Suggest a fix

In ExampleGenerator.resolveModelToExample, the schema should be processed if it is a valid enum (i.e. it has an enum field and that field is a non-empty sequence). This check should be placed here:

} else if (ModelUtils.isArraySchema(schema)) {
return resolvePropertyToExample(schema.getName(), mediaType, schema, processedModels);
} else {
// TODO log an error message as the model does not have any properties
return null;
}

@alexrjones alexrjones changed the title [BUG][yaml] Null example values generated for enum properties [BUG] Null example values generated for enum properties May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant