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
21.23k stars 6.43k forks source link

[REQ] [JAVA] Allow multiple interfaces to be generated for similar URI pattern #6595

Open wolfdale opened 4 years ago

wolfdale commented 4 years ago

Is your feature request related to a problem? Please describe.

Problem : If the URL starts with /animal/mammals Java openapi-generator will generate a API interface as AnimalApi. Suppose we have another URL which starts with /animal/reptiles, the generated APIs interface AnimalApi will have all the APIs of mammals & reptiles together.

For modular design, sometimes it is necessary to segregate the APIs for mammals & reptiles into different classes(with same starting URL - /animal/). In this particular case, it would be helpful if we can generate two separate interface like AnimalMammalApi & AnimalReptileApi.

Right now are no provision for controlling how we generate APIs interfaces.

Describe the solution you'd like

Need to have more control over on how we generate APIs interface.

Describe alternatives you've considered

NA

Additional context

NA

helloworld121 commented 3 years ago

Hi @wolfdale this would be a realy nice feature. I am looking forward for something like this. Thank you, Sebastian

micheleorsi commented 3 years ago

I am interested as well!

adilekinci commented 2 years ago

is there any update on this topic? A feature like this would be very helpful.

zeoe commented 2 years ago

I am interested as well!

maddin79 commented 2 years ago

Would be awesome to have this. If someone points me to the code, I could have a look how to do it.

dwilda commented 1 year ago

don't the tags offer this functionality? tag your operations accordingly and add <useTags>true</useTags> to your plugin configuration's configOptions(assuming maven pom)

isadounikau commented 12 months ago

@dwilda can you please give an example of yaml file, java file and maven configuration

Pierre491 commented 11 months ago

@dwildapuoi fornire un esempio di file yaml, file Java e configurazione Maven

Hi, I attached example yaml and maven-plugin and next put screen of result

yaml ``` openapi: 3.0.0 info: title: testApi contact: {} version: '1.0.0' servers: - url: REPLACE_WITH_ACTUAL_URL variables: {} paths: /animal/mammal/cat: get: tags: - MammalAnimal operationId: cat responses: '200': $ref: '#/components/responses/SimpleResponse' /animal/mammal/dog: get: tags: - MammalAnimal operationId: dog responses: '200': $ref: '#/components/responses/SimpleResponse' /animal/reptile/snake: get: tags: - ReptileAnimal operationId: snake responses: '200': $ref: '#/components/responses/SimpleResponse' /animal/reptile/turtle: get: tags: - ReptileAnimal operationId: turtle responses: '200': $ref: '#/components/responses/SimpleResponse' components: responses: SimpleResponse: description: OK headers: {} content: application/json: schema: $ref: '#/components/schemas/SimpleResponseMessage' schemas: SimpleResponseMessage: title: SimpleResponseMessage type: object properties: name: type: string ```
Maven ``` org.openapitools openapi-generator-maven-plugin ${openapi-generator.version} GenerateSpringAPIs generate generate-sources spring ${project.basedir}/src/main/resources/yaml/test.yaml ${project.build.directory}/generated-sources/ com.mycompany.openapi.model.test com.mycompany.openapi.service spring-boot true true false java8 true false true true false true true true ```

result: image

AnnLuciole commented 5 months ago

You can mark your endpoints with different tags:

/animal/mammals:
  get:
    tags:
      - Mammals
/animal/reptiles:
  get:
    tags:
      - Reptiles

and add configOptions in your build.gradle

openApiGenerate {
    configOptions = [
            useTags: "true",
    ]
}