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

[OpenAPI Generator] Enable allow-list for API and Model classes #530

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

newtork
Copy link
Contributor

@newtork newtork commented Aug 9, 2024

Please find similar setting names in the original OpenAPI generator.

Usage:

  • In additionalProperties define modelsToGenerate and apisToGenerate. Use <space> or , as delimiter.
<plugin>
  <groupId>com.sap.cloud.sdk.datamodel</groupId>
  <artifactId>openapi-generator-maven-plugin</artifactId>
  <configuration>
    <additionalProperties>
      <apisToGenerate>Sodas,Orders</apisToGenerate>
      <modelsToGenerate>
        Order
        OrderWithTimestamp
        Soda
        SodaWithId
      </modelsToGenerate>
    </additionalProperties>

Note:

  • To enable the generation of file SodasApi.java, the apisToGenerate field should contain Sodas (without suffix),
  • If apisToGenerate is not defined, all APIs are allowed. Same with modelsToGenerate.

Definition of Done

  • Functionality scope stated & covered
  • Tests cover the scope above
  • Error handling created / updated & covered by the tests above
  • Documentation updated
  • Release notes updated

@newtork newtork added do not merge Pull request must not be merged please review Request to review a pull request labels Aug 9, 2024
@newtork newtork marked this pull request as draft August 9, 2024 19:23
@newtork
Copy link
Contributor Author

newtork commented Sep 23, 2024

Moved stale PR to personal fork.

@newtork newtork closed this Sep 23, 2024
@newtork newtork reopened this Dec 17, 2024
a-d added 2 commits December 17, 2024 11:33
…s-and-models

# Conflicts:
#	datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/GenerationConfigurationConverter.java
@newtork newtork marked this pull request as ready for review December 17, 2024 10:34
@newtork newtork added please merge Request to merge a pull request and removed do not merge Pull request must not be merged labels Dec 17, 2024
Copy link
Member

@MatKuhr MatKuhr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally lgtm. However, allow-list is not ideal for our purposes. E.g. for orchestration we already have 47 files, and typically we would want to only exclude a few files from generation.

Did you check the options for block-list? Maybe using .openapi-generator-ignore can be made to work?

@@ -115,6 +115,15 @@ private static void setGlobalSettings( @Nonnull final GenerationConfiguration co
GlobalSettings.setProperty(CodegenConstants.HIDE_GENERATION_TIMESTAMP, Boolean.TRUE.toString());
}

private static String getAllowedIds( @Nonnull final GenerationConfiguration config, @Nonnull final String property )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor) a unit test for this would be nice, that would also clarify that both whitespaces and newlines are supported as separators

true,
true,
3,
ofEntries(entry("apisToGenerate", "Default, NotExist"), entry("modelsToGenerate", "Cola,Fanta ,NotExist")));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(question) is this intentional, or should it be:

Suggested change
ofEntries(entry("apisToGenerate", "Default, NotExist"), entry("modelsToGenerate", "Cola,Fanta ,NotExist")));
ofEntries(entry("apisToGenerate", "Default, NotExist"), entry("modelsToGenerate", "Cola, Fanta, NotExist")));

version: 1.0.0
description: API for managing sodas in a soda store
paths:
/sodas:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor) since there is only one API, this only tests that NotExist doesn't cause the generation to fail..

$ref: '#/components/schemas/OneOf'
components:
schemas:
OneOfWithDiscriminatorAndMapping:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor) the following would prevent finding unrelated tests when searching our code base for oneOf:

Suggested change
OneOfWithDiscriminatorAndMapping:
ShouldNotBeGenerated:

@newtork newtork added please review Request to review a pull request and removed please review Request to review a pull request please merge Request to merge a pull request labels Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
please review Request to review a pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants