Skip to content

Commit b0539d7

Browse files
feat: support Swagger 2.0 as input (#378)
Co-authored-by: Maciej Urbańczyk <urbanczyk.maciej.95@gmail.com>
1 parent 29dd73f commit b0539d7

File tree

33 files changed

+45953
-143
lines changed

33 files changed

+45953
-143
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ To see the complete feature list for each language, please click the individual
7373
<td><a href="./docs/usage.md">JSON Schema</a></td>
7474
<td>We support the following JSON Schema versions: <em>Draft-7</em></td>
7575
</tr>
76+
<tr>
77+
<td><a href="./docs/usage.md">OpenAPI</a></td>
78+
<td>We support the following OpenAPI versions: <em>Swagger 2.0</em></td>
79+
</tr>
7680
</table>
7781

7882
<a id="outputs"></a>

docs/README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,14 @@ Contains many advanced ways to integrate Modelina _(i.e. websites)_.
3030
### [Development](./development.md)
3131
Explains how to setup the project for development.
3232

33-
### [Input processing](./input_processing.md)
34-
Details how input processing works.
35-
3633
### [Generators](./generators.md)
3734
Details which different generator options are supported.
3835

3936
### [Presets](./presets.md)
4037
Goes more in-depth into how the preset system works, which enables full customization of generators.
4138

42-
### [Interpretation of JSON Schema draft 7](./interpretation_of_JSON_Schema_draft_7.md)
43-
Explains how a JSON Schema draft 7 schema is interpreted to a data model.
39+
### [Interpretation of JSON Schema](./interpretation_of_JSON_Schema.md)
40+
Explains how a JSON Schema is interpreted to a data model.
4441

4542
### Languages
4643
Each language has its own limitations, corner cases, and features; thus, each language has separate documentation.

docs/input_processing.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

docs/interpretation_of_JSON_Schema_draft_7.md renamed to docs/interpretation_of_JSON_Schema.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Interpretation of JSON Schema draft 7 to CommonModel
1+
# Interpretation of JSON Schema to CommonModel
22

33
The library transforms JSON Schema from data validation rules to data definitions (`CommonModel`(s)).
44

docs/usage.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,36 @@ TODO
2525

2626
## Generate models from AsyncAPI documents
2727

28+
When providing an AsyncAPI document, the library iterates the entire document and generate models for all defined messages. If any other kind of iteration is wanted, feel free to create a [feature request](https://github.com/asyncapi/modelina/issues/new?assignees=&labels=enhancement&template=enhancement.md).
29+
2830
There are two ways to generate models for an AsyncAPI document.
2931

3032
- [Generate from a parsed AsyncAPI document](../examples/asyncapi-from-parser)
3133
- [Generate from a pure JS object](../examples/asyncapi-from-object)
3234

3335
The library expects the `asyncapi` property for the document to be set in order to understand the input format.
3436

37+
The message payloads, since it is a JSON Schema variant, is [interpreted as a such](./interpretation_of_JSON_Schema.md).
38+
3539
## Generate models from JSON Schema draft 7 documents
3640

3741
There are one way to generate models from a JSON Schema draft 7 document.
3842

3943
- [Generate from a pure JS object](../examples/json-schema-draft7-from-object)
4044

41-
The library expects the `$schema` property for the document to be set in order to understand the input format. By default, if no other inputs are detected, it defaults to `JSON Schema draft 7`.
45+
The library expects the `$schema` property for the document to be set in order to understand the input format. By default, if no other inputs are detected, it defaults to `JSON Schema draft 7`. The process of interpreting a JSON Schema to a model can be read [here](./interpretation_of_JSON_Schema.md).
46+
47+
## Generate models from Swagger 2.0 documents
48+
When providing an AsyncAPI document, Modelina iterates the entire document and generate models for all defined `body` parameters and responses. If any other kind of iteration is wanted, feel free to create a [feature request](https://github.com/asyncapi/modelina/issues/new?assignees=&labels=enhancement&template=enhancement.md).
49+
50+
There are one way to generate models from a Swagger 2.0 document
51+
52+
- [Generate from a pure JS object](../examples/swagger2.0-from-object)
53+
54+
The Swagger input processor expects that the property `swagger` is defined in order to know it should be processed.
55+
56+
The response payload and `body` parameters, since it is a JSON Schema variant, is [interpreted as a such](./interpretation_of_JSON_Schema.md).
57+
4258

4359
## Generate Go models
4460
TODO

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This directory contains a series of self-contained examples that you can use as
66
- [asyncapi-from-object](./asyncapi-from-object) - A basic example where an AsyncAPI JS object is used to generate models.
77
- [asyncapi-from-parser](./asyncapi-from-parser) - A basic example where an AsyncAPI JS object from the [parser-js](https://github.com/asyncapi/parser-js) is used to generate models.
88
- [json-schema-draft7-from-object](./json-schema-draft7-from-object) - A basic example where a JSON Schema draft 7 JS object is used to generate models.
9+
- [swagger2.0-from-object](./swagger2.0-from-object) - A basic example where a Swagger 2.0 JS object is used to generate models.
910
- [java-generate-javax-constraint-annotation](./java-generate-javax-constraint-annotation) - A basic example that shows how Java data models having `javax.validation.constraints` annotations can be generated.
1011
- [java-generate-javadoc](./java-generate-javadoc) - A basic example of how to generate Java models including JavaDocs.
1112
- [custom-logging](./custom-logging) - A basic example where a custom logger is used.

examples/TEMPLATE/index.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ describe('Should be able to render TEMPLATE', () => {
77
});
88
test('and should log expected output to console', async () => {
99
await generate();
10+
//Generate is called 2x, so even though we expect 1 model, we double it
1011
expect(spy.mock.calls.length).toEqual(2);
1112
expect(spy.mock.calls[1]).toMatchSnapshot();
1213
});

examples/asyncapi-from-object/index.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ describe('Should be able to process a pure AsyncAPI object', () => {
66
});
77
test('and should log expected output to console', async () => {
88
await generate();
9+
//Generate is called 2x, so even though we expect 1 model, we double it
910
expect(spy.mock.calls.length).toEqual(2);
1011
expect(spy.mock.calls[1]).toMatchSnapshot();
1112
});

examples/asyncapi-from-parser/index.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ describe('Should be able to process AsyncAPI object from parser', () => {
77
});
88
test('and should log expected output to console', async () => {
99
await generate();
10+
//Generate is called 2x, so even though we expect 1 model, we double it
1011
expect(spy.mock.calls.length).toEqual(2);
1112
expect(spy.mock.calls[1]).toMatchSnapshot();
1213
});

examples/json-schema-draft7-from-object/index.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ describe('Should be able to process JSON Schema draft 7 object', () => {
77
});
88
test('and should log expected output to console', async () => {
99
await generate();
10+
//Generate is called 2x, so even though we expect 1 model, we double it
1011
expect(spy.mock.calls.length).toEqual(2);
1112
expect(spy.mock.calls[1]).toMatchSnapshot();
1213
});

0 commit comments

Comments
 (0)