Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit aa6e36f

Browse files
authored
Add kotlin generator, includes schema generation and validation (#431)
* Adds kotlin petstore sample * Changes status to experimental * Updates 2 configuration classes * Converts all exceptions to kotlin * Converts KeywordValidator and supporting classes to Kotlin * Updates kotlin jsonschema templates and supporting classes * Reverts java templates * Updates AdditionalPropertiesValidator * Updates UnsetAnyTypeJsonSchema * Move improvemnts for kotlin code of json schema and unset anytype schema * Updates companion object for unset any type schema * More improvements to UnsetAnyTypeJsonSchema * Fixes more types in UnsetAnyTypeJsonSchema1Boxed * Updates FrozenList and FrozenMap * Updates FrozenList/Map * Reverts java template changes * Fixes all of the type validator interfaces * Updates type validator * Updates FormatValidator * Updates ItemsValidator * Updates RequiredValidator * Updates ExclusiveMaximumValidator * Updates ExclusiveMinimumValidator * Updates max and min items validators * Updates Max and Min length validators * Updates max and min properties validator * Updates max and min validator * Fixes some intelij warnings in the jsonschema class * Updates AllOfValidator * Updates anyof and oneof validators * Updates not and unique items validators * Updates enum + pattern validators * Updates const and contains validator * Updates max and min contains validators * Updates DependentRequiredValidator + PropertyNamesValidator * Updates DependentSchemasValidator + PatternPropertiesValidator * Updates IfValidator + PrefixItemsValidator * Updates ElseValidator + ThenValidator * Updates UnevaluatedItemsValidator + UnevaluatedPropertiesValidator * Updates AnyTypeJsonSchema * Updates NotAnyTypeJsonSchema * Updates BooleanJsonSchema * Adds NullJsonSchema * Updates StringJsonSchema * Updates ListJsonSchema * Updates MapJsonSchema * Updates NumberJsonSchema * Updates DateJsonSchema * Updates DateTimeJsonSchema * Updates DecimalJsonSchema * Adds DoubleJsonSchema * Updates FloatJsonSchema * Updates GenericBuilder * Uses intsAllowedForFloatDoubleFormats in Float/Double schemas * Updates Int32JsonSchema * Updates Int64JsonSchema * Updates IntJsonSchema * Updates SetMaker and UnsetAddPropsSetter Updates UuidJsonSchema Updates AdditionalPropertiesValidatorTest Removes unused kotlin files in petstore Updates the type value method interfaces and enum validators Updates some lingering java code to kotlin Fixes compile errors Fixes JsonSchemaKeywordFlagsTest Fixes JsonSchemaFactory and existing tests FIxes CustomIsoparserTest Updates FormatValidatorTest Updates ItemsValidatorTest Updates JsonSchemaTest Updates PropertiesValidatorTest Updates RequiredValidatorTest Updates TypeValidatorTest Updates AnyTypeSchemaTest Updates ArrayTypeSchemaTest Updates BooleanSchemaTest Updates ListBuilderTest Updates ListSchemaTest Updates MapSchemaTest Updates NullSchemaTest Updates NumberSchemaTest Partial updated to ObjectTypeSchemaTest kt file only More partial updates to ObjectTypeSchemaTest kt file Adds ObjectTypeSchemaTest Partial update of RefBooleanSchemaTest Updates RefBooleanSchemaTest Stops generating api client and rest client if there are no paths in kotlin Kotlin does not generate response sif there are not component responses or paths Makes request body kotlin generation conditional on presence of paths or component request bodies Conditionally generate parameters and headers packages for kotlin 303 sample regen Conditionally generates mediatype in kotlin Kotlin makes contenttype generation conditional Refactors supporting file adding into one method in kotlin Conditionally generate ApiCOnfiguration, fix artifactId warning Conditionally generates ApiException Makes generation of NotImplementedException conditional Updates readme to detect no endpoints, updates readme and gradle settings to use generatorSettings Fixes readme reference to artifactVersion Fixes various kotlin bugs, tests now pass without generated schemas Kotlin 303 regen, component schemas and tests deleted Fixes object output class initialization and requiredProps and optionalProps static vars Fixes object output class property methods Fixes output types for kotlin Fixes kotlin input types Fixes of input type definitions Removes list map and set imports Objects import removed Many schema generation fixes, imports property methods Removes casts because kotlin smart casts Many fixes for builder setter interfaces and methods More improvements to builder setters Fixes setters and builder classes Fixes sealed interfaces for schemas Updates type values Udpates properties, moves JsonSchemaInfo higher Partial validate fix Adds needed schema constructors Updates getNewInstance Fixes broken code in validate methods Removes PropertyEntry, more fixes Fixes many more kotlin errors Fixes some kotlin casting issues Updates schema info list creation to use listOf Updates code to use setOf Fixes array input and output classes Fixes schema extension of primitive json schemas Fixes enum types Fixes json schema enum data Fixes defaultValue method Fixes character escaping Removes many unneeded semicolons Fixes kotlin 303 tests Kotlin 303 sample added to ci Adds kotlin doc Adds circleci test for kotlin tweaks circleci file Turns off kotlinc version printing Checks gradle wrapper version Updates android image Switches image version Changes kotlin image ot use openjdk Removes kotlinc log Updates wrapper invocation Turns on test logging, forces to be rerun * Samples and docs regen * Kotlin 310 sample gen * Updates dependentSchemas * Updates dependentRequired * Updates patternProperties * Includes patternProperties in calculation of mapValueSchema * Omits getKnownKeys method when additionalProperties is turned off * Fixes value checking of lists of any type in map output getters * Fixes output type issues for property getters * Adds 310 kotlin test to ci * Samples regen * Adjusts gradlew command * Update build file to increase the max jvm memory limit when compiling * Removes nodaemon arg on gradle test invocation * Adds info logging to 310 gradle test * Adds info logging * Increases memory to 512 mB * Increases memory to 1 g * Updates template default to 1g * Readme updated
1 parent 9e824ae commit aa6e36f

File tree

1,316 files changed

+224118
-153
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,316 files changed

+224118
-153
lines changed

.circleci/config.yml

+20-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ commands: # a reusable command with parameters
1212
# In many cases you can simplify this from what is generated here.
1313
# 'See docs on artifact collection here https://circleci.com/docs/2.0/artifacts/'
1414
- run: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS
15-
# This is based on your 1.0 configuration file or project settings
16-
- run:
17-
command: java -version
18-
# Test
15+
# Show jobId
1916
- run:
2017
name: "Setup custom environment variables"
2118
command: echo 'export CIRCLE_JOB_ID="<<parameters.jobId>>"' >> $BASH_ENV
@@ -137,6 +134,24 @@ jobs:
137134
key: javaClientMavenCache
138135
paths:
139136
- ~/.m2
137+
testKotlinClientSamples:
138+
docker:
139+
- image: cimg/openjdk:17.0.9
140+
working_directory: ~/OpenAPITools/openapi-json-schema-generator
141+
shell: /bin/bash --login
142+
environment:
143+
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
144+
CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
145+
steps:
146+
- restore_cache:
147+
keys:
148+
- kotlinClientGradleCache
149+
- command_build_and_test:
150+
jobId: "testKotlinClientSamples"
151+
- save_cache:
152+
key: kotlinClientGradleCache
153+
paths:
154+
- ~/build
140155
workflows:
141156
version: 2
142157
build:
@@ -146,3 +161,4 @@ workflows:
146161
- testPython38ClientSamples
147162
- testPython39ClientSamples
148163
- testJava17ClientSamples
164+
- testKotlinClientSamples

.circleci/parallel.sh

+7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ elif [ "$JOB_ID" = "testJava17ClientSamples" ]; then
3333

3434
cat ./.circleci/testJava17ClientSamples.sh | parallel
3535

36+
elif [ "$JOB_ID" = "testKotlinClientSamples" ]; then
37+
echo "Running job $JOB_ID ..."
38+
gradle --version
39+
java -version
40+
41+
cat ./.circleci/testKotlinClientSamples.sh | parallel
42+
3643
else
3744
echo "Running job $JOB_ID"
3845

.circleci/testJava17ClientSamples.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
(cd samples/client/petstore/java && gradle wrapper && gradle test)
1+
(cd samples/client/petstore/java && gradle wrapper && ./gradlew test --no-daemon)
22
(cd samples/client/3_0_3_unit_test/java && mvn test)
33
(cd samples/client/3_1_0_unit_test/java && mvn test)

.circleci/testKotlinClientSamples.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(cd samples/client/3_0_3_unit_test/kotlin && gradle wrapper && ./gradlew cleanTest test -info)
2+
(cd samples/client/3_1_0_unit_test/kotlin && gradle wrapper && ./gradlew cleanTest test -info)

README.md

+27-76
Original file line numberDiff line numberDiff line change
@@ -15,89 +15,40 @@ so developers can use all of those features.
1515

1616
Currently, the following languages/frameworks are supported:
1717

18-
- python (Stability: Stable)
19-
- java (Stability: Stable)
20-
21-
## Join Our Community
22-
We use a Discord server as a place to ask questions and help each other. It offers functionality very similar to Slack.
23-
You can join us here: https://discord.gg/mHB8WEQuYQ
24-
25-
## Reasons To Use the Python Generator
26-
27-
- v3.0.0 - [v3.1.0*](#openapi-v310-support) OpenAPI Specification support
28-
- Type hints on
29-
- schema payload inputs in SomeSchema.validate ![validate screen capture](docs/schema_validate.gif)
30-
- Note: to make input dictionaries TypedDicts like the Money.validate example, set additionalProperties to false in the schema in your openapi document
31-
- schema keyword argument inputs in `SomeSchemaDict.__new__` ![validate screen capture](docs/schemadict_new.gif)
32-
- accessing properties in object instances so some_val in some_val = some_inst.someKey will have the correct type hint ![instance properties screen capture](docs/instance_properties.gif)
33-
- accessing array items in array instances so some_val in some_val = array_inst[0] will have the correct type hint
34-
- endpoint inputs + responses
35-
- Run time type checking and validation checking when:
36-
- instantiating models
37-
- sending to endpoints
38-
- receiving from endpoints
39-
- Note: if needed, validation of json schema keywords can be deactivated via a SchemaConfiguration class
40-
- [mypy](samples/client/petstore/python/test_python.sh) runs on sample petstore client and passes
41-
- passing mypy tests means that this generator could be ported into compiled languages like java/kotlin/golang
42-
- [Autogenerated thorough testing of json schema keyword features in models and endpoints](https://github.com/openapi-json-schema-tools/openapi-json-schema-generator/tree/master/samples/client/3_0_3_unit_test/python/test) which come from the [json schema test suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite)
43-
- [Tests are passing in CI](https://app.circleci.com/pipelines/github/openapi-json-schema-tools/openapi-json-schema-generator?branch=master)
44-
- [Test endpoints are tagged by the relevant keyword like type/format/allOf 39 keywords and counting](https://github.com/openapi-json-schema-tools/openapi-json-schema-generator/tree/master/samples/client/3_1_0_unit_test/python/docs/apis/tags)
45-
- Code re-use built in from the ground up
46-
- components/schemas/headers etc are generated as separate classes and imported when used via $ref
47-
- Openapi spec inline schemas supported at any depth in any location
18+
| Feature | [Python](docs/generators/python.md) | [Java](docs/generators/java.md) | [Kotlin](docs/generators/kotlin.md) |
19+
|----------------------------------------------------------------------------------------------------|-------------------------------------|---------------------------------|-------------------------------------|
20+
| Generator status | stable | stable | experimental |
21+
| Openapi v3.0.0-3.1.0 ingestion | X | X | X |
22+
| Json Schema 2020-12 Support (components/schemas) | X | X | X |
23+
| Component schemas documentation produced | X | X | X |
24+
| Documentation produced for other component types:<br>headers, parameters,requestBodies, ressponses | X | X | |
25+
| Endpoints that send/receive json + docs generated for them | X | X | |
26+
27+
## Reasons To Use the Generators
28+
- Openapi spec support for v3.0.0-3.1.0
29+
- thorough tests run in CI using json schema test suite, see 3_0_0 and 3_1_0 sample clients
30+
- Static analysis:
31+
- mypy run in CI against python petstore sample
32+
- checker framework run w/ NullnessChecker, ensures no null pointer exceptions
4833
- Format support for: int32, int64, float, double, binary, date, datetime, uuid
49-
- Invalid (in python) property names supported like `from`, `1var`, `hi-there` etc in
34+
- Invalid (in language) property names supported like `from`, `1var`, `hi-there` etc in
5035
- schema property names
5136
- endpoint parameter names
37+
- Openapi document inline schemas supported at any depth in any location
38+
- Generated Code: Class + method inputs are typed
39+
- Generated Code: Static type checking done in static languages suing builder inputs and class property access
40+
- Generated Code: run-time type checking done in all generators (a payload can be validated against n schemas)
41+
- Generated Code re-use built in from the ground up
42+
- components/schemas/headers etc are generated as separate classes and imported when used via $ref
5243
- Payload values are not coerced when validated, so a date/date-time value can pass other validations that describe the payload only as type string
53-
- types are generated for enums of type string/integer/boolean using typing.Literal
5444
- String transmission of numbers supported with type: string, format: number, value can be accessed as a Decimal with schemas.as_decimal(inst)
5545
- Multiple content types supported for request and response bodies
56-
- Endpoint response always also includes the urllib3.HTTPResponse
57-
- Endpoint response deserialization can be skipped with the skip_deserialization argument
46+
- Endpoint response always also includes the raw response
47+
- Interfaces kept consistent across generated languages
5848

59-
And many more!
60-
- [Docs for the python generator](docs/generators/python.md)
61-
- [generated client sample code](samples/client/petstore/python)
62-
- [Openapi v3.0.3 general petstore spec, general features](src/test/resources/3_0/python/petstore_customized.yaml)
63-
- [generated v3.1.0 unit test client sample code](samples/client/3_1_0_unit_test/python)
64-
- [Openapi json schema v3.1.0 unit test spec](src/test/resources/3_1/unit_test_spec/3_1_0_unit_test_spec.yaml)
65-
- [generated v3.0.3 unit test client sample code](samples/client/3_0_3_unit_test/python)
66-
- [Openapi json schema v3.0.3 unit test spec](src/test/resources/3_0/unit_test_spec/3_0_3_unit_test_spec.yaml)
67-
68-
## Reasons To Use the Java Generator
69-
70-
- v3.0.0 - [v3.1.0](docs/generators/java.md#schema-feature) OpenAPI Specification support
71-
- Documentation generated in the style of javadocs. Examples: [Money schema](samples/client/petstore/java/docs/components/schemas/Money.md#money1) [Pet.addPet endpoint](samples/client/petstore/java/docs/apis/tags/Pet.md#addpet)
72-
- Sealed classes used to define endpoint responses/response bodies/validated schema payloads/request bodies
73-
- Input types constrained for a Schema in SomeSchema.validate
74-
- validate method can accept arbitrary List/Map/null/int/long/double/float/String json data
75-
- Immutable List output classes generated and returned by validate for List&lt;?&gt; input
76-
- Immutable Map output classes generated and returned by validate for Map&lt;?, ?&gt; input
77-
- Strictly typed list input can be instantiated in client code using generated ListBuilders
78-
- Strictly typed map input can be instantiated in client code using generated MapBuilders
79-
- Sequential map builders are generated ensuring that required properties are set before build is invoked. Looks like:
80-
- `new MapBuilder().requiredA("a").requiredB("b").build()`
81-
- `new MapBuilder().requiredA("a").requiredB("b").optionalProp("c").additionalProperty("someAddProp", "d").build()`
82-
- Run time type checking and validation when
83-
- validating schema payloads
84-
- instantiating List output class (validation run)
85-
- instantiating Map output class (validation run)
86-
- Note: if needed, validation of json schema keywords can be deactivated via a SchemaConfiguration class
87-
- Enums classes are generated and may be input into Schema.validate or the List/MapBuilder add/setter methods
88-
- The [Checker-Framework's](https://github.com/typetools/checker-framework) NullnessChecker and @Nullable annotations are used in the java client
89-
- ensuring that null pointer exceptions will not happen
90-
- Invalid (in java) property names supported like `class`, `1var`, `hi-there` etc in
91-
- component schema names
92-
- schema property names (a fallback setter is written in the MapBuilder)
93-
- Generated interfaces are largely consistent with the python code
94-
- Openapi spec inline schemas supported at any depth in any location
95-
- Format support for: int32, int64, float, double, date, datetime, uuid
96-
- Payload values are not coerced when validated, so a date/date-time value can pass other validations that describe the payload only as type string
97-
- enum types are generated for enums of type string/integer/number/boolean/null
98-
- String transmission of numbers supported with type: string, format: number
99-
- [Autogenerated thorough testing of json schema keyword features in models and endpoints](samples/client/3_0_3_unit_test/java/src/test/java/org/openapijsonschematools/client/components/schemas) which come from the [json schema test suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite)
100-
- [Tests are passing in CI](https://app.circleci.com/pipelines/github/openapi-json-schema-tools/openapi-json-schema-generator?branch=master)
49+
## Join Our Community
50+
We use a Discord server as a place to ask questions and help each other. It offers functionality very similar to Slack.
51+
You can join us here: https://discord.gg/mHB8WEQuYQ
10152

10253
And many more!
10354
- [Docs for the java generator](docs/generators/java.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
generatorName: kotlin
2+
outputDir: samples/client/3_0_3_unit_test/kotlin
3+
inputSpec: src/test/resources/3_0/unit_test_spec/3_0_3_unit_test_spec_nopaths.yaml
4+
intsAllowedForFloatDoubleFormats: true
5+
artifactId: unit-test-api
6+
hideGenerationTimestamp: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
generatorName: kotlin
2+
outputDir: samples/client/3_1_0_unit_test/kotlin
3+
inputSpec: src/test/resources/3_1/unit_test_spec/3_1_0_unit_test_spec_nopaths.yaml
4+
intsAllowedForFloatDoubleFormats: true
5+
artifactId: unit-test-api
6+
hideGenerationTimestamp: true

0 commit comments

Comments
 (0)