Skip to content

Commit b5397a2

Browse files
committed
add support for anyOf and oneOf
1 parent 85941a3 commit b5397a2

File tree

99 files changed

+2131
-127
lines changed

Some content is hidden

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

99 files changed

+2131
-127
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ keywords = ["Swagger", "OpenAPI", "REST"]
44
license = "MIT"
55
desc = "OpenAPI server and client helper for Julia"
66
authors = ["Tanmay Mohapatra <[email protected]>"]
7-
version = "0.1.0"
7+
version = "0.1.1"
88

99
[deps]
1010
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ The order in which middlewares are invoked are:
155155
## TODO
156156

157157
Not all OpenAPI features are supported yet, e.g.:
158-
- [`oneOf`, `anyOf`, `allOf`, `not`](https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/)
158+
- [`not`](https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/)
159159
- [inheritance and polymorphism](https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/)
160160
- [some of the JSON schema keywords](https://swagger.io/docs/specification/data-models/keywords/)
161161
- some [subtler data types](https://swagger.io/docs/specification/data-models/data-types/)

src/commontypes.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
abstract type APIModel end
22
abstract type APIClientImpl end
3+
abstract type UnionAPIModel <: APIModel end
4+
abstract type OneOfAPIModel <: UnionAPIModel end
5+
abstract type AnyOfAPIModel <: UnionAPIModel end
36
struct OpenAPIException <: Exception
47
reason::String
58
end

src/json.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function iterate(w::JSONWrapper, state...)
2424
end
2525

2626
lower(o::T) where {T<:APIModel} = JSONWrapper(o)
27+
lower(o::T) where {T<:UnionAPIModel} = JSONWrapper(o.value)
2728

2829
to_json(o) = JSON.json(o)
2930

@@ -33,6 +34,10 @@ from_json(::Type{T}, json::Dict{String,Any}) where {T <: Dict} = convert(T, json
3334
from_json(::Type{T}, j::Dict{String,Any}) where {T <: String} = to_json(j)
3435
from_json(::Type{Any}, j::Dict{String,Any}) = j
3536

37+
function from_json(o::T, json::Dict{String,Any}) where {T <: UnionAPIModel}
38+
return from_json(o, :value, json)
39+
end
40+
3641
function from_json(o::T, json::Dict{String,Any}) where {T <: APIModel}
3742
jsonkeys = [Symbol(k) for k in keys(json)]
3843
for name in intersect(propertynames(o), jsonkeys)
@@ -42,7 +47,7 @@ function from_json(o::T, json::Dict{String,Any}) where {T <: APIModel}
4247
end
4348

4449
function from_json(o::T, name::Symbol, json::Dict{String,Any}) where {T <: APIModel}
45-
ftype = property_type(T, name)
50+
ftype = (T <: UnionAPIModel) ? property_type(T, name, json) : property_type(T, name)
4651
fval = from_json(ftype, json)
4752
setfield!(o, name, convert(ftype, fval))
4853
return o
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
README.md
2+
docs/AnyOfMappedPets.md
3+
docs/AnyOfPets.md
4+
docs/Cat.md
5+
docs/CatAllOf.md
6+
docs/DefaultApi.md
7+
docs/Dog.md
8+
docs/DogAllOf.md
9+
docs/OneOfMappedPets.md
10+
docs/OneOfPets.md
11+
docs/Pet.md
12+
src/AllAnyClient.jl
13+
src/apis/api_DefaultApi.jl
14+
src/modelincludes.jl
15+
src/models/model_AnyOfMappedPets.jl
16+
src/models/model_AnyOfPets.jl
17+
src/models/model_Cat.jl
18+
src/models/model_CatAllOf.jl
19+
src/models/model_Dog.jl
20+
src/models/model_DogAllOf.jl
21+
src/models/model_OneOfMappedPets.jl
22+
src/models/model_OneOfPets.jl
23+
src/models/model_Pet.jl
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6.3.0-SNAPSHOT
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Julia API client for AllAnyClient
2+
3+
API to test code generation for oneof anyof allof
4+
5+
## Overview
6+
This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://openapis.org) from a remote server, you can easily generate an API client.
7+
8+
- API version: 0.0.1
9+
- Build package: org.openapitools.codegen.languages.JuliaClientCodegen
10+
11+
12+
## Installation
13+
Place the Julia files generated under the `src` folder in your Julia project. Include AllAnyClient.jl in the project code.
14+
It would include the module named AllAnyClient.
15+
16+
Documentation is generated as markdown files under the `docs` folder. You can include them in your project documentation.
17+
Documentation is also embedded in Julia which can be used with a Julia specific documentation generator.
18+
19+
## API Endpoints
20+
21+
Class | Method
22+
------------ | -------------
23+
*DefaultApi* | [**echo_anyof_mapped_pets_post**](docs/DefaultApi.md#echo_anyof_mapped_pets_post)<br/>**POST** /echo_anyof_mapped_pets<br/>
24+
*DefaultApi* | [**echo_anyof_pets_post**](docs/DefaultApi.md#echo_anyof_pets_post)<br/>**POST** /echo_anyof_pets<br/>
25+
*DefaultApi* | [**echo_oneof_mapped_pets_post**](docs/DefaultApi.md#echo_oneof_mapped_pets_post)<br/>**POST** /echo_oneof_mapped_pets<br/>
26+
*DefaultApi* | [**echo_oneof_pets_post**](docs/DefaultApi.md#echo_oneof_pets_post)<br/>**POST** /echo_oneof_pets<br/>
27+
28+
29+
## Models
30+
31+
- [AnyOfMappedPets](docs/AnyOfMappedPets.md)
32+
- [AnyOfPets](docs/AnyOfPets.md)
33+
- [Cat](docs/Cat.md)
34+
- [CatAllOf](docs/CatAllOf.md)
35+
- [Dog](docs/Dog.md)
36+
- [DogAllOf](docs/DogAllOf.md)
37+
- [OneOfMappedPets](docs/OneOfMappedPets.md)
38+
- [OneOfPets](docs/OneOfPets.md)
39+
- [Pet](docs/Pet.md)
40+
41+
42+
## Authorization
43+
Endpoints do not require authorization.
44+
45+
46+
## Author
47+
48+
49+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# AnyOfMappedPets
2+
3+
4+
5+
## Properties
6+
Name | Type | Description | Notes
7+
------------ | ------------- | ------------- | -------------
8+
**value** | This is a anyOf model. The value must be any of the following types: Cat, Dog | | [optional]
9+
10+
The discriminator field is `pet_type` with the following mapping:
11+
- `cat`: `Cat`
12+
- `dog`: `Dog`
13+
14+
15+
16+
17+
[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md)
18+
19+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# AnyOfPets
2+
3+
4+
5+
## Properties
6+
Name | Type | Description | Notes
7+
------------ | ------------- | ------------- | -------------
8+
**value** | This is a anyOf model. The value must be any of the following types: Cat, Dog | | [optional]
9+
10+
The discriminator field is `pet_type`
11+
12+
13+
14+
[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md)
15+
16+

0 commit comments

Comments
 (0)