* Adds addComposedMappedModels and testComposedSchemaOneOfDiscriminatorMap
* Requires that discriminators be required properties
* Strengthens discriminaotr validation, adds better error messages, adds schema oneof samples
* Adds oneOf and anyOf invalidDiscriminator tests
* Updates incorrect addOneOfInterfaceModel invocation
* Runs ensure-up-to-date
* Adds updates from Sebastien Rosset
* Removes newlines
* Uses df.isString
* Fixes tests be correctly setting df.isString
* Updates discriminatorExplicitMappingVerbose description per PR feedback
* Adds description of how mappedModels is populated
* Adds the suggestion exception raising when a MappedModel mappingName is null
* Actually resolves merge conflicts
* Switches two methods to package private because they are needed for testing
* Allow nulls in MappedModel.getMappingName
* Updates CLI flag name to legacyDiscriminatorBehavior, default=true
Co-authored-by: William Cheng <wing328hk@gmail.com>
-D option has been deprecated as it was previously used to:
* Pass "system properties"
* Pass additional properties
This was confusing because we already have --additional-properties and
because Java System Properties are passed as -D before program
arguments.
Confusion around the -D option had existed for some time, but when we
introduced the thread-safe GlobalSettings to avoid overwriting Java
System Properties, we created a hard break from Java System Properties
in the generator. This also disconnected the previous "system
properties" from accepting additional properties.
Once these newly deprecated methods are removed, we will have a clear
separation of concerns between:
* Java System Properties
* Global generator properties (used as workflow context)
* Additional properties (used as generator options)
This commit marks multiple places for cleanup in 5.0. These will be
breaking changes, and lower effort to break in 5.0 with deprecation
warnings now rather than adding sibling properties throughout the code
and potentially introducing logic errors.
* [cli] Some CLI improvements…
* Introduce --version
* Introduce --help
* Add --sha to version command for short SHA display
* Output Version and SHA details
* In new --version output, display repo and doc site
Additional cleanup to suppress warnings and code quality.
* [docker] Adds labels for metadata
This adds image labels to store metadata on the online and cli docker
images, using standard labels:
* org.opencontainers.image.created
* org.opencontainers.image.revision
* org.opencontainers.image.title
* org.opencontainers.image.version
These can be inspected via 'docker inspect IMAGE_NAME' and may be useful
in tooling/automation or bug reports submitted by users.
For more details on these labels, see:
https://github.com/opencontainers/image-spec/blob/master/annotations.md
* Include version --full for equiv to --version
* [cli] Validate now uses parseOptions w/setResolve
The validate command now uses ParseOptions#setResolve(true) to match how
we parse in CodegenConfigurator and online's Generate. Without this
option, the OpenAPI 3 parser skips the "resolve" block, which made lead
to validations in the command not matching validations during
generation.
* [gradle] Validate now uses parseOptions w/setResolve
The Graldle validate command now uses ParseOptions#setResolve(true) to match how
we parse in CodegenConfigurator and online's Generate. Without this
option, the OpenAPI 3 parser skips the "resolve" block, which made lead
to validations in the command not matching validations during
generation.
When I originally implemented the feature set code, I added the
getter/setter on DefaultCodegen and CodegenConfig as well as on
GeneratorMetadata. GeneratorMetadata also includes the library variation
features. When I went to add library-specific features, I realized the
discrepancy.
This removes the public setter from DefaultCodegen/CodegenConfig, and
adds a protected modifyFeatureSet which accepts a lambda and hides the
builder logic away in the method.
This will be a breaking change for anyone who's created a custom
generator in 4.2.3, so the impact is very limited.
* 👕🎨 Minor refactor DefaultGenerator
This cleans up some lint warnings and improve general code cleanliness
of DefaultGenerator.
Specifically:
* logger strings are now using the built-in log formatter rather than
constructing new strings regardless of log level.
* Diamond operators are used where possible
* Some long-unused commented code has been removed
* Lambdas are used where possible
* Redundant operations are merged (HashMap constructor used rather than
subsequent putAll on a collection, for example)
* [cli][core] Add support for dry-run and display
CLI now supports `--dry-run`, which will output a file change status
similar to git status --porcelain.
The user may also specify `--verbose` for a one-liner below each file
explaining why the change operation might take place.
* [docs] Upgrade to Docusaurus 2
Due to formatting issues with Docusaurus 1 and code blocks, and upcoming
4.3 and 5.0 releases, this is an upgrade to have more control over
formatting and other functionality.
This adds behavior to have light/dark themes.
As a consequence of upgrading, columnar format on ul element in
generated generator docs had to be moved to css. This will not impact
users viewing the markdown on GitHub because it didn't display the
column format.
This upgrade should improve syntax highlighting and performance.
* Fix user page layout, choose theme with clear diff colors
* [core] Normalizing vendor extension naming
According to [OAS 2.0][1] and [OAS 3.0][2] Specifications:
> Allows extensions to the OpenAPI Schema. The field name MUST begin with x-,
> for example, x-internal-id. The value can be null, a primitive, an array or an object.
> Can have any valid JSON format value.
This commit attempts to define a [clear identifier design format][3] of
maintaining lower-kebab casing and following the x- prefix defined by
OAI Specification.
Following a convention that matches that used by others (see [autorest][4]), we will remove
any confusion about naming strategies for template authors and
customizers. Following the lower-kebab convention will allow us to
convert from camelCase and missing prefixes to the desired format. For
example, these conversions are simple to make for template consistency:
* customValue => x-custom-value
* x-customValue => x-custom-value
* x-custom-value => x-custom-value
This convention also allows us to define a single standard for use
across all generators. This means no occurrence of x-operationId in one
generator and x-operation-id in another.
[1]: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#patterned-objects
[2]: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#specificationExtensions
[3]: https://tools.ietf.org/html/draft-wilde-registries-01#section-3.4
[4]: https://github.com/Azure/autorest/tree/master/docs/extensions
* Incorporate feedback to avoid race/blocking in OnceLogger
* Remove unnecessary additional log config
* Add tests,comments for OnceLogger
* Test caffeine cache with FakeTicker
* Flatten feature sets for display
* [cli] Add feature set output to config-help
This includes markdown and plain text outputs for config-help.
* [docs] FeatureSet on generator docs
* [core] Extracting recommendations to validation framework
This is work to extract recommendation logic out of the CLI validate command
into a shared evaluation instance which can be used elsewhere (such as Gradle,
or the Online tool).
For now, these validations are in addition to those provided by swagger-parser and
are only the following recommendations:
* Apache/Nginx warning that header values with underscore are dropped by default
* Unused models/schemas
* Use of properties with oneOf, which is ambiguous in OpenAPI Specification
I've allowed for disabling recommendations via System properties, since this is
something that has been requested a few times by users. System properties in this
commit include:
* openapi.generator.rule.recommendations=false
- Allows for disabling recommendations completely. This wouldn't include all warnings
and errors, only those we deem to be suggestions
* openapi.generator.rule.apache-nginx-underscore=false
- Allows for disabling the Apache/Nginx warning when header names have underscore
- This is a legacy CGI configuration, and doesn't affect all web servers
* openapi.generator.rule.oneof-properties-ambiguity=false
- We support this functionality, but the specification may not intend for it
- This is more to reduce noise
* openapi.generator.rule.unused-schemas=false
- We will warn when a schema is not referenced outside of Components, which
users have requested to be able to turn off
* openapi.generator.rule.anti-patterns.uri-unexpected-body=false
* Move recommendation/validations to oas package and add javadoc comments
* Refactor and test recommendation validations
* Refactor validation function signatures to return explicit state rather than boolean
* Add operation recommendation for GET/HEAD w/body
* Spotbugs, PMD and Checkstyle #33
* Reducing Spotbugs effort to min #33
* Also using project.parent.basedir and avoiding relative paths in pom files.
* Filtering out samples.
* Move PMD/Spotbugs to static-analysis profile
This moves the static-analysis checks to a standalone profile. Core
contributors may run static analysis with:
```
mvn -Pstatic-analysis install
```
The analysis is separated from default functionality to reduce impact to
community contributions. SpotBugs/PMD may add a non-trivial amount of
time to builds on some machines.
Co-authored-by: Tomas Bjerre <tomas.bjerre85@gmail.com>
* 🐛 Fixing some issues with threading and NPE
After running Sonar on the master branch, some major analysis
opportunities were displayed.
This fixes the use of SimpleDateFormat stored as static fields.
SimpleDateFormat is not thread-safe, and may retain data across threads.
While there's no indicator that this has caused any issues (these are
mostly used for example code), we should follow these best practices.
This also fixes a handful of NPE and other minor issues such as
comparing Boolean.TRUE to strings and no wrapping some closeables in
try-with-resources.
* [cli] Unit test GenerateBatch custom deserialization helper
* Quiet batch mode in sonar.yml
* Suppress unnecessary warnings (ThreadLocals in static fields)
* [test] Removes jmockit in favor of mockito
We use mockito in many tests. This removes jmockit which is run as a
javaagent in favor of Mockito which is not.
This work is in preparation for applying some static analysis tools,
while evaluating others such as Jacoco. I'm also look at ways to improve
build times while also decreasing "ramp up time" for contributions from
the community. Reducing the number of mock frameworks and dependencies
is a step toward that goal.
* Rename method in new.sh
* [cli] Mock the generate task
* [config-help] Sort all outputs
* Remove old/stale generator docs (these have been renamed previously)
* Sort config doc outputs, making it easier to find relevant info
* Fixes cliOptions duplicates
Erlang client/proper improperly set the version option as packageName
(causing duplicate for packageName).
The java and swift option removals are because the options are added in
parent classes, resulting in duplication of the options.
* Add --github-nested-index for generating docs/generators/README.md
* 📝 Regenerate generator docs
OAS 3.x specification isn't entirely clear on oneOf support. JSON Schema
defines oneOf in such a way that the Schema is only valid if it
validates against exactly one of the referenced Schemas. This suggests
that a Schema defined with oneOf can't include additional "dynamic"
properties. OpenAPI extends on this by adding the necessary
discriminator object, which allows tooling to decide the intended
Schema.
As tooling, openapi-generator may support loose or confusing definitions
in the Specification to better support our user's use cases. In this
case, we may warn that while this usage is technically valid the two
target specifications are unclear about the actual constraints regarding
oneOf.
* [cli][batch] Better glob support
If invoked as `openapi-generator batch *.yaml`, the command might
previously fail in some shells where `*.yaml` expands to file name only.
This supports globs without path-part in the filename to prevent
possible NPE.
* [cli] Document batch command
* [meta] Support Kotlin meta generator
* Guard against automatic scripts (assumptions for this script are not fulfilled by some CI which run "run all" type scripts)