Is it possible to exclude paths in Openapi code generation?
Asked Answered
P

1

9

We are using a large third party API with many optional features. There are 27 endpoints and we need only a few of these from Maven. We are using server side generation.

If you are interested the API is here: https://github.com/mjeffrey/psd2 Ideally we would only generate and expose the ones we support.

Is it possible to just generate a list of API endpoints or exclude ones we don't want to support?

I see there is the possibility to generate only certain models but that is not what we need. the -D apis parameter seems tor be treated as a boolean in the source code.

https://github.com/OpenAPITools/openapi-generator#3---usage https://github.com/OpenAPITools/openapi-generator/blob/master/docs/customization.md#selective-generation

I'm also considering a pre-processor so we don't need to manually edit the yaml file (which is updated regularly). Any suggestions for preprocessing the yaml file?

Pa answered 17/4, 2019 at 13:29 Comment(0)
P
3

The way to do this is to use the environment variable apis and provide a comma separated list of the root path-segment. Unfortunately in our case the root is /v1 so we get only one "api" generated and we can't select individual paths.

Stripping off the /v1 from all the paths we can then use:

Command line

java -Dapis="consents,{payment-service},accounts"

Maven

<configuration>
  <environmentVariables>
    <apis>consents,{payment-service},accounts</apis>
  </environmentVariables>
</configuration>
Pa answered 18/4, 2019 at 8:26 Comment(1)
this answer is very useful, are the APIs excluded or generated? do you have any sample/ example where we can exclude some models (defined in a common package as external YAMLs that we reference inside the API yaml) from the generation process. thank you.Fertilization

© 2022 - 2024 — McMap. All rights reserved.