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

Feature Request: Swagger Maven Plugin should be able to read Swagger config #3133

Closed
patrickfav opened this issue Feb 22, 2019 · 4 comments
Closed

Comments

@patrickfav
Copy link
Contributor

patrickfav commented Feb 22, 2019

Currently the maven plugin allows for reading a openapiFilePath which expects the file to have the openApi element as root, like so:

info:
  version: '1.0.0'
  title: REST API
  description: 'The REST API description.'
  contact:
    email: mail@mail.com
  license:
    name: All Rights Reserved
    url: https://license.com
  x-logo:
    url: https://logo.svg
    backgroundColor: "#FFFFFF"
externalDocs:
  description: Docs
  url: 'http://docs/Glossar'

However, if one already uses Swagger to dynamically serve the doc over a e.g. Servlet, one usually has a Swagger configuration file with this scheme:

resourcePackages:
  - my.package
prettyPrint: false
cacheTTL: 0
openAPI:
  info:
    version: '1.0.0'
    title: REST API
    description: 'The REST API description.'
    contact:
      email: mail@mail.com
    license:
      name: All Rights Reserved
      url: https://license.com
    x-logo:
      url: https://logo.svg
      backgroundColor: "#FFFFFF"
  externalDocs:
    description: Docs
    url: 'http://docs/Glossar'

As there is no trivial way to include yaml in yaml, I now would have to maintain 2 openApi configs.

My suggestion is therefore this:
Provide a new config named configurationFilePath swaggerConfigurationFilePath which accepts a path to a configuration file as described in https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-Configuration#configuration-file. This file would be parsed before the other configs and has less precedence as a maven plugin defined config. E.g. if provided a resourcePackages defined config in maven pom would have higher precedence of the same config defined in the swagger yaml config.


Is the team interested in such a feature? I am willing to provide a PR for this.

@frantuma
Copy link
Member

frantuma commented Feb 22, 2019

This sounds very good indeed, and it is for sure interesting, possibly applicable also to gradle-plugin. Maybe the config name could be configurationFilePath

@patrickfav
Copy link
Contributor Author

patrickfav commented Feb 22, 2019

Alright, then Id prepare the PR in the next couple of days. I would start with the maven plugin. When we agree on the exact requirement and behaviour, this can then be ported to the Gradle plugin.

Maybe the config name could be configurationFilePath

You are right, this is probably better.

@frantuma
Copy link
Member

excellent thx!

patrickfav added a commit to patrickfav/swagger-core that referenced this issue Mar 10, 2019
Currently the maven plugin only accepted OpenAPI files. This adds
the option to provide a swagger configuration (e.g. prettyPrint),
so if you already have a config file for say, serving a life api doc,
you don't have to define it twice.

This heavily refactors the maven plugin and adds a bunch of tests. Also
the readme is extended to reflect the new parameter. The error handling
for file reading was changed to fail-fast, meaning, if a user provides
the config, the file must exist and must be readable, otherwise an error
is thrown. This makes it easier to correctly set the plugin up.
patrickfav added a commit to patrickfav/swagger-core that referenced this issue Mar 10, 2019
Currently the maven plugin only accepted OpenAPI files. This adds
the option to provide a swagger configuration (e.g. prettyPrint),
so if you already have a config file for say, serving a life api doc,
you don't have to define it twice.

This heavily refactors the maven plugin and adds a bunch of tests. Also
the readme is extended to reflect the new parameter. The error handling
for file reading was changed to fail-fast, meaning, if a user provides
the config, the file must exist and must be readable, otherwise an error
is thrown. This makes it easier to correctly set the plugin up.
patrickfav added a commit to patrickfav/swagger-core that referenced this issue Mar 10, 2019
Currently the maven plugin only accepted OpenAPI files. This adds
the option to provide a swagger configuration (e.g. prettyPrint),
so if you already have a config file for say, serving a life api doc,
you don't have to define it twice.

This heavily refactors the maven plugin and adds a bunch of tests. Also
the readme is extended to reflect the new parameter. The error handling
for file reading was changed to fail-fast, meaning, if a user provides
the config, the file must exist and must be readable, otherwise an error
is thrown. This makes it easier to correctly set the plugin up.
frantuma added a commit that referenced this issue Mar 15, 2019
Add swagger config file option to maven plugin (#3133)
@frantuma
Copy link
Member

#3150 merged, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants