openapi-processor / openapi-processor-core

moved into openapi-processor-base
Apache License 2.0
7 stars 5 forks source link

modelNameSuffix #65

Closed aegliv closed 3 years ago

aegliv commented 3 years ago

Hi,

awesome project, thanks for putting in the hours!

The openapi-generator-maven-plugin has a configuration property called modelNameSuffix which, as the name suggest, allows the user to append a suffix to the generated model classes.

Do you thing such a feature would be valuable in your project as well?

Example

Swagger:

components:
  schemas:
    FooObject:
      type: object
      properties:
        bar:
          type: boolean

Mapping:

openapi-processor-mapping: v2

options:
   package-name: example.gen

   modelNameSuffix: Dto

Would result in the generation of example.gen.model.FooObjectDto.java

hauner commented 3 years ago

Funny, haven't thought of that. :-)

Yes, I guess this would be useful. That way we can avoid the postfix "noise" in the openapi description, which is our current strategy at work.. ;-)

aegliv commented 3 years ago

Wow, seems that you went along and implemented it already?

If I can give you a hand or test your solution just give me a mention!

hauner commented 3 years ago

Started it :-) It does not work yet. I still have a few failing tests.

Giving it a test run would be nice, I'll notify you when it is ready to try.

hauner commented 3 years ago

@aegliv I think it should work now. Tests pass but I haven't tried it on a real project yet.

You can try the latest openapi-processor-spring snapshot (2021.4-SNAPSHOT) (or openapi-processor-micronaut 2021.2-SNAPSHOT). Just update the version.

The mapping looks like this:

openapi-processor-mapping: v2

options:
  package-name: generated
  model-name-suffix: Resource

It will ignore the suffix if the schema already ends with the suffix to ease migration.

aegliv commented 3 years ago

Thanks for the quick implementation! But where did you release your snapshot version? Can't find it on mvn central...

hauner commented 3 years ago

Hi @aegliv,

it is on maven central (https://oss.sonatype.org/#nexus-search;quick~openapiprocessor), the central snapshots repository is: https://oss.sonatype.org/content/repositories/snapshots

if you are using the gradle plugin (2021.3) it should automatically find it (the plugin adds the snapshots repository), if you are using the maven plugin (2021.1) you probably need to add the repository.

    <pluginRepositories>

        <pluginRepository>
            <id>openapi-processor-snapshots</id>
            <name>openapi-processor-snapshots</name>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </pluginRepository>

    </pluginRepositories>
hauner commented 3 years ago

released with 2021.4

aegliv commented 3 years ago

Thanks, works like a charm!

Sry I could not test it earlier but my company's firewall did not let me download your SNAPSHOT version

hauner commented 3 years ago

Thanks, nice to hear that it works for you :-)