1

I'm trying to read the properties of each object in the Schema field from an OpenAPI 3 specification.

I used a loop to read the schema field from this OpenAPI 3 spec but now I need to retrieve the name of each property. Here is my code :

Map<String, Schema> definitions = swagger.getComponents().getSchemas();

                for (Map.Entry<String, Schema> path : definitions.entrySet())
                {  

                System.out.println(path.getKey() + "/" + path.getValue().getProperties());

                }

I expect an output like this :

Pet/[id]
NewPet/[name,tag]
Error/[code, message]

But this is the snippet of the actual output:

    Pet/null
    NewPet/{name=class StringSchema {
    class Schema {
        title: null
        multipleOf: null
        maximum: null
        exclusiveMaximum: null
        minimum: null
        exclusiveMinimum: null

All I need is to retrieve the value that precedes the "=class", in this case "name"

Linda Naoui
  • 147
  • 13
  • Could you please elaborate on what your use case is? Is this related to [your previous](https://stackoverflow.com/questions/57036547/is-there-a-way-to-convert-openapi-specifications-to-json-mappings-in-maven) [questions](https://stackoverflow.com/questions/56989445/is-there-a-way-to-convert-an-openapi-specification-to-a-spring-cloud-contract)? There might be a better/easier solution depending on the use case. – Helen Jul 29 '19 at 15:54
  • 1
    For example, if you are trying to convert an OpenAPI definition into another format, you could create a [custom generator](https://github.com/swagger-api/swagger-codegen#making-your-own-codegen-modules) for [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) instead. If you want to generate JSON/XML payload examples for a specific schema, there's [`ExampleBuilder`](https://stackoverflow.com/q/55978052/113116) for that. – Helen Jul 29 '19 at 19:01
  • 1
    Yes it's related to my previous question, I want to generate JSON examples for a specific schema. I tried to use the link of the ExampleBuilder added some modifications and now it works!! – Linda Naoui Jul 30 '19 at 08:39

0 Answers0