Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please enhance ExampleBuilder class #470

Open
clemi2408 opened this issue Apr 15, 2024 · 0 comments
Open

Please enhance ExampleBuilder class #470

clemi2408 opened this issue Apr 15, 2024 · 0 comments

Comments

@clemi2408
Copy link

--> 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 );

                }

            }
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant