180 Commits

Author SHA1 Message Date
William Cheng
1d606499ee Merge remote-tracking branch 'origin/5.0.x' 2020-05-06 22:51:05 +08:00
William Cheng
003165c2c2
Prepare 4.3.1 release (#6187)
* prepare 4.3.1 release

* update doc
2020-05-06 17:10:31 +08:00
Jim Schubert
cc623ba429
[cli][build] Relax the git id plugin (#6094)
* [cli][build] Relax the git id plugin

* Guard against null on missing build properties
2020-04-30 08:49:07 -04:00
William Cheng
46216cd796 Merge remote-tracking branch 'origin/master' into 5.0.x 2020-04-28 20:35:28 +08:00
Justin Black
8e8471c1fd
[CORE] Fixes composed schema discriminator map (#4906)
* 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>
2020-04-25 00:01:02 +08:00
William Cheng
8fa76843d0 resolve merge conflicts in the core generator files 2020-04-17 16:10:10 +08:00
William Cheng
faf6f197be Merge remote-tracking branch 'origin/master' into 5.0-sync-master 2020-04-17 15:51:00 +08:00
Jim Schubert
2957dd4d45
[cli] Add --global-property for -D replacement (#5687)
-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.
2020-04-02 11:11:02 +08:00
Jim Schubert
e14e5fccf3
[cli][docker] Better expose version/sha information of builds (#5736)
* [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
2020-04-02 11:05:25 +08:00
William Cheng
a0ca253218
update samples (#5722) 2020-03-27 13:55:55 +08:00
William Cheng
c224cf484b
4.3.0 release (#5721) 2020-03-27 11:34:43 +08:00
Jim Schubert
f6f5c9b8b9
[cli][gradle] Validate now uses parseOptions w/setResolve (#5471)
* [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.
2020-03-01 17:26:13 +08:00
Jim Schubert
36b1a61b70
[all] Move feature set setter (#5460)
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.
2020-02-28 14:45:06 +08:00
Jim Schubert
db47b95fc9
[cli][core] Add support for dry-run and display (#5332)
* 👕🎨 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.
2020-02-18 20:36:17 -05:00
Henré Botha
930afadc87
Fix docs for --enable-post-process-file (#5299) 2020-02-13 15:07:07 +08:00
Henré Botha
324fe70ab3
Edit documentation for -c (#5288) 2020-02-13 15:05:52 +08:00
Jim Schubert
aa7cd4f5af
[docs] Upgrade to Docusaurus 2 (#5271)
* [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
2020-02-11 21:22:58 +08:00
Jim Schubert
8d6286dfae
[core] Normalizing vendor extension naming (#5192)
* [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
2020-02-06 22:52:58 +08:00
William Cheng
100b01844a Merge remote-tracking branch 'origin/master' into 5.0.x 2020-02-04 15:31:10 +08:00
Jim Schubert
97ff9b4be7
[cli] Optional colorized outputs (#5193) 2020-02-02 17:36:53 -05:00
Jim Schubert
a496c2011f
[docs] Initial FeatureSet generator documentation (#5188)
* 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
2020-02-01 20:51:55 -05:00
Jim Schubert
22c6c0ca68
[core] Extracting recommendations to validation framework (#4979)
* [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
2020-01-31 12:19:16 -05:00
William Cheng
03a59046f4 Merge remote-tracking branch 'origin/4.3.x' 2020-01-31 19:00:28 +08:00
William Cheng
26ace1337d
Prepare 4.2.3 release (#5172)
* release 4.2.3

* update readme
2020-01-31 16:24:06 +08:00
Jim Schubert
c0f7b47292
[ci][test] Modifications to static analysis contribution via Tomasbjerre (#5116)
* 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>
2020-01-26 12:45:41 -05:00
Jim Schubert
c9ec084418
🐛 Fixing some issues with threading and NPE (#5107)
* 🐛 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)
2020-01-25 18:28:16 -05:00
Jim Schubert
ac528aaf07
[test] Removes jmockit in favor of mockito (#5063)
* [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
2020-01-22 18:04:00 -05:00
William Cheng
82e2448bf2 Merge remote-tracking branch 'origin/4.3.x' into 5.0.x 2020-01-20 15:46:13 +08:00
William Cheng
04af5e0445 Merge remote-tracking branch 'origin/master' into 4.3.x 2020-01-20 15:04:34 +08:00
Jim Schubert
644f720db8
[docs] Sorted doc outputs and clean up duplicated CliOptions (#5046)
* [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
2020-01-19 20:19:11 -05:00
Jim Schubert
ea55968737
Evaluating https issues in CircleCI (on top of CiscoM31-maven-h… (#5034)
* replace http with https. Replace http://central.maven.org with https://repo1.maven.org

* replace http://www.apache.org/licenses/LICENSE-2.0 with https://www.apache.org/licenses/LICENSE-2.0

* Force HTTPS for mavenCentral gradle DSL

Co-authored-by: Sebastien Rosset <serosset@cisco.com>
2020-01-18 18:53:05 -05:00
valery1707
b22fde6caa Use UTF-8 charset on writing files (#4984) 2020-01-13 15:26:56 +08:00
Jim Schubert
e23f2aa6aa
[cli] Full config help details (#4928)
* [cli] Dump additional generator info via config-help (plain text)
* [cli] Dump additional generator info via config-help (markdown)
2020-01-07 13:33:58 -05:00
William Cheng
466a67c9bc Merge remote-tracking branch 'origin/4.3.x' into 5.0.x 2019-12-12 17:27:49 +08:00
William Cheng
3e34903042 Merge remote-tracking branch 'origin/master' into 4.3.x 2019-12-11 15:44:50 +08:00
Jim Schubert
0c0050578f
User feedback on confusing use of oneOf (#4695)
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.
2019-12-07 11:27:29 -05:00
William Cheng
11c7007429
Prepare v4.2.3 (#4663)
* update version

* update doc

* update samples
2019-12-02 15:26:01 +08:00
William Cheng
f9662e0eff
release 4.2.2 (#4661) 2019-12-02 13:12:10 +08:00
William Cheng
7aeab0219c Merge remote-tracking branch 'origin/4.3.x' into 5.0.x 2019-11-23 11:37:54 +08:00
William Cheng
275d1db2e5 Merge remote-tracking branch 'origin/master' into 4.3.x 2019-11-22 23:15:12 +08:00
Jim Schubert
c89d21a903 [cli][doc] Document batch command (#4572)
* [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
2019-11-22 11:09:08 +08:00
William Cheng
facabd4472 Merge branch '4.3.x' into 5.0.x 2019-11-21 15:19:31 +08:00
William Cheng
60f4de0f22 Merge remote-tracking branch 'origin/master' into 4.3.x 2019-11-20 18:15:22 +08:00
William Cheng
f07b3e0521
Prepare 4.2.2-SNAPSHOT (#4497)
* update to 4.2.2-SNAPSHOT

* update doc

* update samples

* skip ocaml test

* update version

* fix version
2019-11-15 21:34:25 +08:00
William Cheng
2683dd4510
Prepare 4.2.1 release (#4494)
* prepare 4.2.1 release

* use stable version in test/example
2019-11-15 16:07:03 +08:00
Jim Schubert
357f6caed5
[meta] Support Kotlin meta generator (#4156)
* [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)
2019-11-09 10:47:55 -05:00
William Cheng
4824bb7711 sync master, update samples 2019-11-04 09:28:19 +08:00
William Cheng
47e2c0d027
update samples (#4334) 2019-10-31 13:31:49 +08:00
William Cheng
34070bd151
Prepare 4.2.0 release (#4333)
* remove snapshot

* update doc
2019-10-31 11:36:53 +08:00
wing328
54151891cc Merge branch 'master' into 5.0.x 2019-10-17 11:18:57 +08:00