2

I have a YAML file and I want to generate equivalent class of this YAML file by OpenAPI code generator (openapi-generator-maven-plugin). my YAML file is something like this:

penapi: 3.0.3
info:
  title: blah blah
  description: blah blah
  version: 1.0.0
components:
  schemas:
    Object1Model:
      description: requested array of object2
      type: object
      properties:
        object2Model:
          type: array
          items:
            $ref: '#/components/schemas/Object2Model'

    Object2Model:
      description: Object2 Model
      type: object
      required:
        - "field1"
        - "field2"
      properties:
        field1:
          description: field1
          type: string
        field2:
          description: field2
          type: string
        day1:
          $ref: "../../commons.yml#/definitions/weekday"
        day2:
          $ref: "../../commons.yml#/definitions/weekday"
paths: { }        

I have weekday enum in another file:

swagger: "2.0"
info:
  title: Commons file
  description: Common elements used across all of the REST APIs
  version: 1.0.0
paths: {}

definitions:
#  Weekday enum used to represent the weekdays.
  weekday:
    type: string
    enum:
      - MON
      - TUE
      - WED
      - THU
      - FRI
      - SAT
      - SUN
    description: Day of a week.
    example: FRI

and my YAML file referes correctly to this file. I want to use Weekday enum generated by Commons file and use existing enum, but OpenAPI generates it again. How can I avoid generating Weekday enum?

1
  • Is your implementation generation duplicate Weekend enum? Commented Jun 1, 2024 at 7:48

1 Answer 1

1

There is a similar problem here. This may help you.

https://stackoverflow.com/a/75825153

You should also check out import or schema mappings for the openapi generator maven plugin. Documentation maven plugin

When you generate your commons models in the first stage of your openapi-generator-maven-plugin configuration, you should be able to use the schema mappings for the second generation stage of the plugin with your main spec.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.