Skip to content

Commit 5d95579

Browse files
committed
update
1 parent ca64c4c commit 5d95579

File tree

2 files changed

+16
-77
lines changed

2 files changed

+16
-77
lines changed

README.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ It is usable, it is used as the internal openapi parser/validator by openapi-pro
2929
a Java 11 based link:{openapi}[OpenAPI] 3.2, 3.1, 3.0 parser with validation and pluggable document reader & json/yaml converter.
3030

3131
* parse OpenAPI 3.2, 3.1 & 3.0
32-
* validate OpenAPI 3.2, 3.1 & 3.0 (json schema validation, can follow $ref's in the OpenAPI document)
32+
* validate OpenAPI 3.2, 3.1 & 3.0 (JSON schema validation, can follow $ref's in the OpenAPI document)
3333
* separate apis for OpenAPI 3.2, 3.1 & 3.0
3434
* easily get resolved $ref object
3535
* bundle & write (single file) OpenAPI document
36+
* apply overlay to (bundled) OpenAPI document (experimental)
3637
* minimal dependencies
3738
* pluggable document reader
3839
* pluggable json/yaml converter

openapi-parser/README.adoc

Lines changed: 14 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
:overlay: https://spec.openapis.org/overlay/v1.0.0.html
33
:converter-jackson: https://github.com/openapi-processor/openapi-parser/tree/master/io-jackson
44
:converter-snakeyaml: https://github.com/openapi-processor/openapi-parser/tree/master/io-snakeyaml
5+
:sample: https://github.com/openapi-processor/openapi-parser/blob/master/openapi-parser/src/test/java/io/openapiparser/samples/ParserSampleTest.java
56

67
**work in progress**
78

@@ -14,17 +15,16 @@ source code gifts (i.e. pull requests) are welcome :-)
1415

1516
== openapi-parser & validator
1617

17-
a Java 11 based link:{openapi}[OpenAPI] 3.0.x & 3.1 parser with validation and pluggable document reader & json/yaml converter.
18+
a Java 11 based link:{openapi}[OpenAPI] 3.2, 3.1 & 3.0 parser with validation, bundling & overlay support and pluggable document reader & json/yaml converter.
1819

19-
* parse OpenAPI 3.0.x & 3.1
20-
* validate OpenAPI 3.0.x & 3.1 (handles $ref's in the OpenAPI document)
20+
* parse OpenAPI 3.2, 3.1 & 3.0
21+
* validate OpenAPI 3.2, 3.1 & 3.0 (JSON schema validation, can follow $ref's in the OpenAPI document)
2122
** JSON schema draft-4 validation of OpenAPI 3.0
22-
** JSON schema draft-2020-12 validation of OpenAPI 3.1
23-
* separate apis for OpenAPI 3.0 & 3.1
23+
** JSON schema draft-2020-12 validation of OpenAPI 3.2, 3.1
24+
* separate apis for OpenAPI 3.2, 3.1 & 3.0
2425
* easily get resolved $ref object
25-
* bundle multi-file OpenAPI documents (experimental)
26-
* write bundled single-file OpenAPI document (json or yaml) (experimental)
27-
// * apply link:{overlay}[Overlays] (experimental)
26+
* bundle & write (single file) OpenAPI document
27+
* apply overlay to (bundled) OpenAPI document (experimental)
2828
* minimal dependencies
2929
* pluggable document reader
3030
* pluggable json/yaml converter
@@ -38,7 +38,7 @@ the parser tries to provide a *user-friendly* api in the sense that it
3838
* throws if *required* properties are not set
3939
* it is *read only*
4040
* it resolves `$ref` objects, i.e. $ref objects have a `getRefObject()`
41-
* it is very close to the specification (OpenAPI 3.0 & 3.1)
41+
* it is very close to the specification (OpenAPI 3.2, 3.1 & 3.0)
4242

4343
Drawback is, that with the current api it is not possible (for some properties) to detect if a property is set in the OpenAPI description or if it is not given.
4444

@@ -80,83 +80,21 @@ For example the `required` property of a `parameter` has a `false` default value
8080

8181
=== yaml/json converter
8282

83-
the *parser* is internally using `Map<String, Object>` to represent the OpenAPI object tree to be independent of a specific yaml/json parser. It will work with any yaml/json parser that is able to convert an OpenAPI yaml or json to a `Map<String, Object>` object tree.
83+
the *parser* is internally using `Map<String, Object>` to represent the OpenAPI object tree to be independent of a specific yaml/json parser. It will work with any yaml/json parser that is able to convert an OpenAPI YAML or JSON to a `Map<String, Object>` object tree.
8484

8585
link:{converter-jackson}[`io-jackson`] provides a default implementation that is based on jackson.
8686

8787
== usage
8888

89-
code example for parsing an OpenAPI yaml file and running the JSON Schema validation.
89+
=== current api (since 2023.3)
9090

91-
=== 2023.3 api (current)
91+
this removes the `Resolver` from the previous (i.e. 2023.2) setup at step 2.
9292

93-
this removes the `Resolver` from the previous (i.e 2023.2) setup at step 2.
93+
The following link:{sample}[sample code] shows the usage of the current api.
9494

9595
[source,java]
9696
----
97-
package io.openapiparser;
98-
99-
import io.openapiparser.model.v30.OpenApi;
100-
import io.openapiparser.model.v30.PathItem;
101-
import io.openapiprocessor.interfaces.Converter;
102-
import io.openapiprocessor.interfaces.Reader;
103-
import io.openapiprocessor.jsonschema.reader.UriReader;
104-
import io.openapiprocessor.jsonschema.schema.*;
105-
import io.openapiprocessor.jsonschema.validator.Validator;
106-
import io.openapiprocessor.jsonschema.validator.ValidatorSettings;
107-
import io.openapiprocessor.snakeyaml.SnakeYamlConverter;
108-
import org.junit.jupiter.api.Test;
109-
110-
import java.util.Collection;
111-
112-
public class SetupExampleTest {
113-
114-
//@Test
115-
void parseAndValidate () {
116-
// 1. create a document loader.
117-
// It loads a document by uri and converts it to a Map<String, Object>
118-
// object tree that represents the OpenAPI document. The parser
119-
// operates on that Object tree which makes it independent of the
120-
// object mapper (e.g. jackson, snakeyaml etc.).
121-
// Both (Reader and Converter) have a very simple interface which makes
122-
// it easy to implement your own.
123-
Reader reader = new UriReader ();
124-
Converter converter = new SnakeYamlConverter ();
125-
// Converter converter = new JacksonConverter ();
126-
DocumentLoader loader = new DocumentLoader (reader, converter);
127-
128-
// 2. create a parser.
129-
DocumentStore documents = new DocumentStore ();
130-
OpenApiParser parser = new OpenApiParser (documents, loader);
131-
132-
// 3. parse the OpenAPI from resource or url.
133-
// here it loads an OpenAPI document from a resource file, but URI works too.
134-
OpenApiResult result = parser.parse ("openapi.yaml");
135-
136-
// 4. get the API model from the result to navigate the OpenAPI document.
137-
// OpenAPI 3.1.x with model.v31.OpenAPI import
138-
OpenApi model = result.getModel (OpenApi.class);
139-
140-
// 5. navigate the model
141-
PathItem pathItem = model.getPaths ().getPathItem ("/foo");
142-
143-
// 6. create Validator to validate the OpenAPI schema.
144-
SchemaStore store = new SchemaStore (loader);
145-
ValidatorSettings settings = new ValidatorSettings ();
146-
Validator validator = new Validator (settings);
147-
148-
// 7. validate the OpenAPI schema.
149-
boolean valid = result.validate (validator, store);
150-
151-
// 8. print validation errors
152-
Collection<ValidationError> errors = result.getValidationErrors ();
153-
ValidationErrorTextBuilder builder = new ValidationErrorTextBuilder ();
154-
155-
for (ValidationError error : errors) {
156-
System.out.println (builder.getText(error));
157-
}
158-
}
159-
}
97+
include::src/test/java/io/openapiparser/samples/ParserSampleTest.java[]
16098
----
16199

162100
=== 2023.2 api (obsolete)

0 commit comments

Comments
 (0)