3

I want to parse any complex swagger-API-document(swagger.json) to Java objects.

may be List>

what are available options?

I am trying with io.swagger.parser.SwaggerParser.

but want to make sure that I know other available options and I use the correct parser which suffices to parse any complex document.

currently we are trying as below.

public  List<Map<String,Object>> parse(String swaggerDocString) throws SwaggerParseException{
    try{
        Swagger swagger = new SwaggerParser().parse(swaggerDocString);
        return processSwagger(swagger);
    }catch(Exception ex){
        String exceptionRefId=OSGUtil.getExceptionReferenceId();
        logger.error("exception ref id " + exceptionRefId +  " : Error while loading swagger file " + ex);
        throw new SwaggerParseException("", ex.getLocalizedMessage(),exceptionRefId);
    }
}

public  List<Map<String,Object>> processSwagger(Swagger swagger){
    List<Map<String,Object>>  finalResult=new ArrayList<>();
    Map<String, Model>  definitions = swagger.getDefinitions();
    // loop all the available paths of the swagger
    if(swagger.getPaths()!=null && swagger.getPaths().keySet()!=null &&swagger.getPaths().keySet().size()>0 ){
        swagger.getPaths().keySet().forEach(group->{
            //get the path
            Path path=swagger.getPath(group);
            //list all the operations of the path
            Map<HttpMethod,Operation> mapList=path.getOperationMap();
            mapList.forEach((httpMethod,operation)->{
                processPathData(finalResult,operation,path,group,httpMethod,definitions,group);
            });

        });
    }
    return finalResult;
}

whats the differences between

swagger-compat-spec-parser, swagger-parser

1 Answer 1

2

swagger has the implementations for all the technologies. https://swagger.io/tools/open-source/open-source-integrations/

and details for parsing swagger into Java is here. https://github.com/swagger-api/swagger-parser/tree/v1

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.