@@ -9,97 +9,113 @@ This Java package is automatically generated by the [OpenAPI JSON Schema Generat
99
1010## Requirements
1111
12- Java 17
12+ 1 . Java 17
13+ 2 . Gradle
1314
1415## Migration Guides
15- - [ 3.0.0 Migration Guide] ( migration_3_0_0.md )
16- - [ 2.0.0 Migration Guide] ( migration_2_0_0.md )
17- - [ Migration from Other Python Generators] ( migration_other_python_generators.md )
16+ - [ Migration from Other Java Generators] ( migration_other_java_generators.md )
1817
1918
2019## Installation
21- ### pip install
2220
23- If the python package is hosted on a repository, you can install directly using :
21+ To install the API client library to your local Maven repository, simply execute :
2422
25- ``` sh
26- pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git
23+ ``` shell
24+ mvn clean install
2725```
28- (you may need to run ` pip ` with root permission: ` sudo pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git ` )
2926
30- Then import the package:
31- ``` python
32- import org.openapijsonschematools.client
27+ To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:
28+
29+ ``` shell
30+ mvn clean deploy
3331```
3432
35- ### Setuptools
33+ Refer to the [ OSSRH Guide] ( http://central.sonatype.org/pages/ossrh-guide.html ) for more information.
34+
35+ ### Maven users
3636
37- Install via [ Setuptools ] ( http://pypi.python.org/pypi/setuptools ) .
37+ Add this dependency to your project's POM:
3838
39- ``` sh
40- python -m pip install . --user
39+ ``` xml
40+ <dependency >
41+ <groupId >org.openapijsonschematools</groupId >
42+ <artifactId >petstore</artifactId >
43+ <version >0.0.1</version >
44+ <scope >compile</scope >
45+ </dependency >
4146```
42- (or ` python -m pip install . ` to install the package for all users)
4347
44- Then import the package:
45- ``` python
46- import org.openapijsonschematools.client
48+ ### Others
49+
50+ At first generate the JAR by executing:
51+
52+ ``` shell
53+ mvn clean package
4754```
4855
56+ Then manually install the following JARs:
57+
58+ - ` target/petstore-0.0.1.jar `
59+ - ` target/lib/*.jar `
60+
61+
4962## Usage Notes
5063### Validation, Immutability, and Data Type
51- This python code validates data to schema classes and return back an immutable instance containing the data
52- which subclasses all validated schema classes. This ensure that
64+ This Java code validates data to schema classes and return back an immutable instance containing the data. This ensure that
5365- valid data cannot be mutated and become invalid to a set of schemas
5466 - the one exception is that files are not immutable, so schema instances storing/sending/receiving files are not immutable
5567
56- Here is the mapping from json schema types to python subclassed types:
68+ Here is the mapping from json schema types to Java types:
69+
5770| Json Schema Type | Java Base Class |
58- | ---------------- | ----------------- |
71+ | ---------------- | --------------- |
5972| object | FrozenMap (HashMap) |
6073| array | FrozenList (ArrayList) |
6174| string | String |
62- | number | Number, float, double, int, long |
63- | integer | int, long |
75+ | number | Number (int, long, float, double) |
76+ | integer | int, long, float, double (with values equal to integers) |
6477| boolean | boolean |
6578| null | Void (null) |
6679| AnyType (unset) | Object |
6780
68- ### Storage of Json Schema Definition in Python Classes
81+ ### Storage of Json Schema Definition in Java JsonSchema Classes
6982In openapi v3.0.3 there are ~ 28 json schema keywords. Almost all of them can apply if
70- type is unset. I have chosen to separate the storage of json schema definition info and output
71- validated classes for payload instantiation.
83+ type is unset. I have chosen to separate the storage of
84+ - json schema definition info
85+ - output classes for validated Map (json schema type object) payloads
86+ - output classes for validated List (json schema type array) payloads
7287
7388<details >
7489 <summary >Reason</summary >
7590
7691This json schema data is stored in each class that is written for a schema, in a component or
7792other openapi document location. This class is only responsible for storing schema info.
78- Output classes like those that store dict payloads are written separately and are
79- returned by the Schema .validate method when that method is passed in dict input.
93+ Output classes like those that store map payloads are written separately and are
94+ returned by the JsonSchema .validate method when that method is passed in Map input.
8095This prevents payload property access methods from
8196colliding with json schema definition.
8297</details >
8398
8499### Json Schema Type Object
85100Most component schemas (models) are probably of type object. Which is a map data structure.
86101Json schema allows string keys in this map, which means schema properties can have key names that are
87- invalid python variable names. Names like:
102+ invalid Java variable names. Names like:
88103- "hi-there"
89104- "1variable"
90105- "@now "
91106- " "
92107- "from"
93108
94- To allow these use cases to work, schemas.immutabledict is used as the base class of type object schemas.
95- This means that one can use normal dict methods on instances of these classes.
109+ To allow these use cases to work, FrozenMap (which extends HashMap) is used as the base class of type object schemas.
110+ This means that one can use normal Map methods on instances of these classes.
96111
97112<details >
98113 <summary >Other Details</summary >
99114
100- - optional properties which were not set will not exist in the instance
101- - None is only allowed in as a value if type: "null" was included or nullable: true was set
102- - preserving the original key names is required to properly validate a payload to multiple json schemas
115+ - getters are written for validly named required and optional properties
116+ - null is only allowed in as a value if type: "null" was included or nullable: true was set
117+ - because null is an allowed property value, it is not used to represent an unset property state
118+ - if an optional property is requested and it does not exist in the Map, an UnsetPropertyException is thrown
103119</details >
104120
105121### Json Schema Type + Format, Validated Data Storage
@@ -131,24 +147,12 @@ is stored as a string.
131147
132148## Getting Started
133149
134- Please follow the [ installation procedure] ( #installation ) and then run the following:
150+ Please follow the [ installation procedure] ( #installation ) and then use the JsonSchema classes in
151+ org.openapijsonschematools.client.components.schemas to validate input payloads and instances of validated Map and List
152+ output classes. Json schemas allow multiple types for one schema, so a schema's validate method can have
153+ allowed input and output types.
135154
136155
137- ## Servers
138- | server_index | Class | Description |
139- | ------------ | ----- | ----------- |
140- | 0 | [ Model0] ( docs/servers/0.md ) | |
141-
142- ## Endpoints
143-
144- All URIs are relative to the selected server
145- - The server is selected by passing in server_info and server_index into api_configuration.ApiConfiguration
146- - Code samples in endpoints documents show how to do this
147- - server_index can also be passed in to endpoint calls, see endpoint documentation
148-
149- | HTTP request | Method | Description |
150- | ------------ | ------ | ----------- |
151-
152156## Component Schemas
153157
154158| Class | Description |
@@ -241,23 +245,3 @@ All URIs are relative to the selected server
241245| [ UriReferenceFormat.UriReferenceFormat1] ( docs/components/schemas/UriReferenceFormat.md#urireferenceformat1 ) | |
242246| [ UriTemplateFormat.UriTemplateFormat1] ( docs/components/schemas/UriTemplateFormat.md#uritemplateformat1 ) | |
243247
244- ## Notes for Large OpenAPI documents
245- If the OpenAPI document is large, imports in org.openapijsonschematools.client.apis.tags.tag_to_api and org.openapijsonschematools.client.components.schemass may fail with a
246- RecursionError indicating the maximum recursion limit has been exceeded. In that case, there are a couple of solutions:
247-
248- Solution 1:
249- Use specific imports for apis and models like:
250- - tagged api: ` from org.openapijsonschematools.client.apis.tags.default_api import DefaultApi `
251- - api for one path: ` from org.openapijsonschematools.client.apis.paths.some_path import SomePath `
252- - api for one operation (path + verb): ` from org.openapijsonschematools.client.paths.some_path.get import ApiForget `
253- - single model import: ` from org.openapijsonschematools.client.components.schemas.pet import Pet `
254-
255- Solution 2:
256- Before importing the package, adjust the maximum recursion limit as shown below:
257- ```
258- import sys
259- sys.setrecursionlimit(1500)
260- import org.openapijsonschematools.client
261- from org.openapijsonschematools.client.apis.tags.tag_to_api import *
262- from org.openapijsonschematools.client.components.schemass import *
263- ```
0 commit comments