swagger-parser
swagger-parser copied to clipboard
get path extension from swagger 2
Hi, is there way how can i get extension form 'paths' level (while parse swagger 2)?
According to spec https://swagger.io/specification/v2/#pathsObject paths can contain
-
/{path}
-> PathItemObject -
^x-
-> Any
eg:
swagger: "2.0"
info:
title: api name
version: 1.0.0
paths:
x-my-extension:
type: HTTP_BACKEND
url: https://example.com/mock
/alerts/KS:
get:
description: description if operation
responses:
'200':
description: Successful Response
schema:
type: object
Swagger.getPaths()
returns Map<String, Path>
, but i did not find way how to access extension.
Tried on 1.0.51
No way: https://github.com/swagger-api/swagger-parser/blob/v1.0.51/modules/swagger-parser/src/main/java/io/swagger/parser/util/SwaggerDeserializer.java#L183
hi @klokane should x-my-extension have the two dots like this: x-my-extension:
?
@gracekarina sure, you are right. I wrong copy example, sorry
I edit original question and correct it.
We are looking into it!
BTW, maybe it can be enough to access it via SwaggerDeserializer::ParseResult::getUnsupported()
https://github.com/swagger-api/swagger-parser/blob/v1.0.51/modules/swagger-parser/src/main/java/io/swagger/parser/util/SwaggerDeserializer.java#L1673
But in current version (1.0.51) is SwaggerDeserializer::ParseResult
protected and it is public unaccessible
Hi, @klokane thanks for pointing this issue into our direction, We have looked into it and due it's an old version of the spec and the complexity of resolving it, we can't prioritize a fix at the moment. We do support paths.extension in OAS 3. Thanks.
Okay. Thank for your time. Do you plan to fix it at least at conversion swagger to oas3
Double checked, and it's the same complex fix.
@klokane, in the meantime, you could access the unsupported
in SwaggerDeserializer::ParseResult
by extending deserializer, e.g. like:
public class MySwaggerDeserializer extends SwaggerDeserializer{
@Override
public MySwaggerDeserializationResult deserialize(JsonNode rootNode) {
MySwaggerDeserializationResult result = new MySwaggerDeserializationResult();
ParseResult rootParse = new ParseResult();
Swagger swagger = parseRoot(rootNode, rootParse);
result.unsupported = rootParse.getUnsupported();
result.setSwagger(swagger);
result.setMessages(rootParse.getMessages());
return result;
}
static class MySwaggerDeserializationResult extends SwaggerDeserializationResult{
public Map<Location, JsonNode> unsupported = new LinkedHashMap<>();
}
}