Skip to content

Please enhance ExampleBuilder class #470

Description

@clemi2408

--> https://github.com/swagger-api/swagger-inflector/blob/master/src/main/java/io/swagger/oas/inflector/examples/ExampleBuilder.java

and add something like this to create proper regex

else if (property instanceof StringSchema stringSchema) {
            
            if (example != null) {
                output = new StringExample(example.toString());
            } else {
                String defaultValue = stringSchema.getDefault();

                if( defaultValue == null && stringSchema.getPattern() ==null){
                    List<String> enums = stringSchema.getEnum();
                    if( enums != null && !enums.isEmpty()) {
                        defaultValue = enums.get(0);
                    }
                }
                
                if(Objects.nonNull(stringSchema.getPattern())){

                    output = new StringExample(RgxGen.parse(stringSchema.getPattern()).generate());

                }
                else{
                    output = new StringExample( defaultValue == null ? SAMPLE_STRING_PROPERTY_VALUE : defaultValue );

                }

            }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions