use of io.swagger.v3.oas.models.info.Info in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIncompatibleRefs.
@Test
public void testIncompatibleRefs() {
String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "paths:\n" + " /test:\n" + " post:\n" + " responses:\n" + " '200':\n" + " $ref: '#/components/schemas/Schema'\n" + " '400':\n" + " definitions: this is right\n" + " description: Bad Request\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " $ref: '#/components/schemas/Schema'\n" + " requestBody:\n" + " content:\n" + " application/json:\n" + " schema:\n" + " $ref: '#/components/schemas/Schema'\n" + " required: true\n" + "info:\n" + " version: ''\n" + " title: ''\n" + "components:\n" + " schemas:\n" + " Schema: {}";
SwaggerParseResult result = new OpenAPIV3Parser().readContents(yaml, null, null);
assertNotNull(result.getOpenAPI());
}
use of io.swagger.v3.oas.models.info.Info in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testParseRefPathParameters.
@Test
public void testParseRefPathParameters() throws Exception {
String yaml = "openAPI: '2.0'\n" + "info:\n" + " title: test\n" + " version: '0.0.0'\n" + "parameters:\n" + " report-id:\n" + " name: id\n" + " in: path\n" + " type: string\n" + " required: true\n" + "paths:\n" + " /reports/{id}:\n" + " parameters:\n" + " - $ref: '#/parameters/report-id'\n" + " put:\n" + " parameters:\n" + " - name: id\n" + " in: body\n" + " required: true\n" + " schema:\n" + " $ref: '#/components/schemas/report'\n" + " responses:\n" + " 200:\n" + " description: ok\n" + "definitions:\n" + " report:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: string\n" + " name:\n" + " type: string\n" + " required:\n" + " - id\n" + " - name\n";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
OpenAPI openAPI = (parser.readContents(yaml, null, null)).getOpenAPI();
}
use of io.swagger.v3.oas.models.info.Info in project swagger-parser by swagger-api.
the class ResolverCacheTest method testLoadExternalRefResponseWithNoContent.
@Test
public void testLoadExternalRefResponseWithNoContent() throws Exception {
final RefFormat format = RefFormat.URL;
final String ref = "http://my.company.com/path/to/main.yaml";
final String contentsOfExternalFile = "openapi: 3.0.0\n" + "\n" + "info:\n" + " version: 1.0.0\n" + " title: Response include test case child\n" + "\n" + "components:\n" + " responses:\n" + " 200:\n" + " description: Success\n";
new Expectations() {
{
RefUtils.readExternalUrlRef(ref, format, auths, "http://my.company.com/path/parent.json");
times = 1;
result = contentsOfExternalFile;
}
};
ResolverCache cache = new ResolverCache(openAPI, auths, "http://my.company.com/path/parent.json");
ApiResponse response = cache.loadRef(ref + "#/components/responses/200", RefFormat.URL, ApiResponse.class);
assertNotNull(response);
assertEquals(response.getDescription(), "Success");
assertNull(response.getContent());
}
use of io.swagger.v3.oas.models.info.Info in project swagger-parser by swagger-api.
the class OAIDeserializationTest method testDeserializeSimpleDefinition.
@Test
public void testDeserializeSimpleDefinition() throws Exception {
String json = "{\n" + " \"openapi\": \"3.0.1\",\n" + " \"info\": {\n" + " \"title\": \"Swagger Petstore\",\n" + " \"description\": \"This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.\",\n" + " \"termsOfService\": \"http://swagger.io/terms/\",\n" + " \"contact\": {\n" + " \"email\": \"apiteam@swagger.io\"\n" + " },\n" + " \"license\": {\n" + " \"name\": \"Apache 2.0\",\n" + " \"url\": \"http://www.apache.org/licenses/LICENSE-2.0.html\"\n" + " },\n" + " \"version\": \"1.0.0\"\n" + " }\n" + "}";
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readContents(json, null, options);
assertNotNull(result.getOpenAPI());
}
use of io.swagger.v3.oas.models.info.Info in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testConverterIssue17.
@Test
public void testConverterIssue17() throws Exception {
String yaml = "openapi: 3.0.0\n" + "info:\n" + " version: 0.0.0\n" + " title: nada\n" + "paths:\n" + " /persons:\n" + " get:\n" + " parameters:\n" + " - name: testParam\n" + " in: query\n" + " style: form\n" + " schema:\n" + " type: array\n" + " items:\n" + " type: string\n" + " responses:\n" + " '200':\n" + " description: Successful response\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " $ref: '#/components/schemas/Content'\n" + "components:\n" + " schemas:\n" + " Content:\n" + " type: object";
ParseOptions options = new ParseOptions();
options.setResolve(false);
SwaggerParseResult result = new OpenAPIV3Parser().readContents(yaml, null, options);
assertNotNull(result.getOpenAPI());
assertEquals((result.getOpenAPI().getPaths().get("/persons").getGet().getResponses().get("200").getContent().get("*/*").getSchema()).get$ref(), "#/components/schemas/Content");
}
Aggregations