forked from loafle/openapi-generator-original
parent
23ad9f3937
commit
9fa9b115e3
@ -50,7 +50,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -89,14 +88,9 @@ public class ModelUtils {
|
|||||||
public static List<String> getUnusedSchemas(OpenAPI openAPI) {
|
public static List<String> getUnusedSchemas(OpenAPI openAPI) {
|
||||||
List<String> unusedSchemas = new ArrayList<String>();
|
List<String> unusedSchemas = new ArrayList<String>();
|
||||||
|
|
||||||
// no model defined
|
|
||||||
if (openAPI.getComponents().getSchemas() == null) {
|
|
||||||
openAPI.getComponents().setSchemas(new HashMap<String, Schema>());
|
|
||||||
}
|
|
||||||
|
|
||||||
// operations
|
// operations
|
||||||
Map<String, PathItem> paths = openAPI.getPaths();
|
Map<String, PathItem> paths = openAPI.getPaths();
|
||||||
Map<String, Schema> schemas = openAPI.getComponents().getSchemas();
|
Map<String, Schema> schemas = getSchemas(openAPI);
|
||||||
|
|
||||||
if (paths != null) {
|
if (paths != null) {
|
||||||
for (String pathname : paths.keySet()) {
|
for (String pathname : paths.keySet()) {
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||||
|
* Copyright 2018 SmartBear Software
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.openapitools.codegen.utils;
|
||||||
|
|
||||||
|
import io.swagger.parser.OpenAPIParser;
|
||||||
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
|
import io.swagger.v3.parser.core.models.ParseOptions;
|
||||||
|
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ModelUtilsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEnsureNoDuplicateProduces() {
|
||||||
|
final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/ping.yaml", null, new ParseOptions()).getOpenAPI();
|
||||||
|
List<String> unusedSchemas = ModelUtils.getUnusedSchemas(openAPI);
|
||||||
|
Assert.assertEquals(unusedSchemas.size(), 0);
|
||||||
|
}
|
||||||
|
}
|
13
modules/openapi-generator/src/test/resources/3_0/ping.yaml
Normal file
13
modules/openapi-generator/src/test/resources/3_0/ping.yaml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
openapi: 3.0.1
|
||||||
|
info:
|
||||||
|
title: ping test
|
||||||
|
version: '1.0'
|
||||||
|
servers:
|
||||||
|
- url: 'http://localhost:8000/'
|
||||||
|
paths:
|
||||||
|
/ping:
|
||||||
|
get:
|
||||||
|
operationId: pingGet
|
||||||
|
responses:
|
||||||
|
'201':
|
||||||
|
description: OK
|
Loading…
x
Reference in New Issue
Block a user