We are in process of removing support for OpenApi 2 (aka Swagger).
As a preparation rename the majority of swagger classes to openapi
classes.
We will eliminate the remaining SwaggerObject class in next patch.
JIRA: NETCONF-984
Change-Id: I848314da6d8f2a4a5efe3ebc8dcf7b0cd46fee53
Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
*
* @author Thomas Pantelis
*/
-public class ApiDocGeneratorRFC8040 extends BaseYangSwaggerGeneratorRFC8040 {
+public class ApiDocGeneratorRFC8040 extends BaseYangOpenApiGeneratorRFC8040 {
public ApiDocGeneratorRFC8040(final DOMSchemaService schemaService) {
super(Optional.of(schemaService));
}
import org.opendaylight.mdsal.dom.api.DOMMountPointService;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
import org.opendaylight.netconf.sal.rest.doc.api.ApiDocService;
-import org.opendaylight.netconf.sal.rest.doc.mountpoints.MountPointSwagger;
+import org.opendaylight.netconf.sal.rest.doc.mountpoints.MountPointOpenApi;
import org.opendaylight.netconf.sal.rest.doc.openapi.CommonApiObject;
import org.opendaylight.netconf.sal.rest.doc.openapi.MountPointInstance;
import org.opendaylight.netconf.sal.rest.doc.openapi.SwaggerObject;
// Query parameter
private static final String PAGE_NUM = "pageNum";
- private final MountPointSwagger mountPointSwaggerRFC8040;
+ private final MountPointOpenApi mountPointOpenApiRFC8040;
private final ApiDocGeneratorRFC8040 apiDocGeneratorRFC8040;
@Inject
@Activate
public ApiDocServiceImpl(final @Reference DOMSchemaService schemaService,
final @Reference DOMMountPointService mountPointService) {
- this(new MountPointSwaggerGeneratorRFC8040(schemaService, mountPointService),
+ this(new MountPointOpenApiGeneratorRFC8040(schemaService, mountPointService),
new ApiDocGeneratorRFC8040(schemaService));
}
@VisibleForTesting
- ApiDocServiceImpl(final MountPointSwaggerGeneratorRFC8040 mountPointSwaggerGeneratorRFC8040,
+ ApiDocServiceImpl(final MountPointOpenApiGeneratorRFC8040 mountPointOpenApiGeneratorRFC8040,
final ApiDocGeneratorRFC8040 apiDocGeneratorRFC8040) {
- mountPointSwaggerRFC8040 = requireNonNull(mountPointSwaggerGeneratorRFC8040).getMountPointSwagger();
+ mountPointOpenApiRFC8040 = requireNonNull(mountPointOpenApiGeneratorRFC8040).getMountPointOpenApi();
this.apiDocGeneratorRFC8040 = requireNonNull(apiDocGeneratorRFC8040);
}
final DefinitionNames definitionNames = new DefinitionNames();
final SwaggerObject doc = apiDocGeneratorRFC8040.getAllModulesDoc(uriInfo, definitionNames);
- return Response.ok(BaseYangSwaggerGenerator.convertToOpenApi(doc)).build();
+ return Response.ok(BaseYangOpenApiGenerator.convertToOpenApi(doc)).build();
}
/**
@Override
public synchronized Response getListOfMounts(final UriInfo uriInfo) {
- final List<MountPointInstance> entity = mountPointSwaggerRFC8040
+ final List<MountPointInstance> entity = mountPointOpenApiRFC8040
.getInstanceIdentifiers().entrySet().stream()
.map(MountPointInstance::new).collect(Collectors.toList());
return Response.ok(entity).build();
@Override
public synchronized Response getMountDocByModule(final String instanceNum, final String module,
final String revision, final UriInfo uriInfo) {
- final CommonApiObject api = mountPointSwaggerRFC8040.getMountPointApi(uriInfo, Long.parseLong(instanceNum),
+ final CommonApiObject api = mountPointOpenApiRFC8040.getMountPointApi(uriInfo, Long.parseLong(instanceNum),
module, revision);
return Response.ok(api).build();
}
final String stringPageNum = uriInfo.getQueryParameters().getFirst(PAGE_NUM);
final Optional<Integer> pageNum = stringPageNum != null ? Optional.of(Integer.valueOf(stringPageNum))
: Optional.empty();
- api = mountPointSwaggerRFC8040.getMountPointApi(uriInfo, Long.parseLong(instanceNum), pageNum);
+ api = mountPointOpenApiRFC8040.getMountPointApi(uriInfo, Long.parseLong(instanceNum), pageNum);
return Response.ok(api).build();
}
}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public abstract class BaseYangSwaggerGenerator {
+public abstract class BaseYangOpenApiGenerator {
- private static final Logger LOG = LoggerFactory.getLogger(BaseYangSwaggerGenerator.class);
+ private static final Logger LOG = LoggerFactory.getLogger(BaseYangOpenApiGenerator.class);
private static final String API_VERSION = "1.0.0";
private static final String SWAGGER_VERSION = "2.0";
MAPPER.configure(SerializationFeature.INDENT_OUTPUT, true);
}
- protected BaseYangSwaggerGenerator(final Optional<DOMSchemaService> schemaService) {
+ protected BaseYangOpenApiGenerator(final Optional<DOMSchemaService> schemaService) {
this.schemaService = schemaService.orElse(null);
}
*
* @author Thomas Pantelis
*/
-public abstract class BaseYangSwaggerGeneratorRFC8040 extends BaseYangSwaggerGenerator {
+public abstract class BaseYangOpenApiGeneratorRFC8040 extends BaseYangOpenApiGenerator {
private final String basePath;
- protected BaseYangSwaggerGeneratorRFC8040(final Optional<DOMSchemaService> schemaService) {
+ protected BaseYangOpenApiGeneratorRFC8040(final Optional<DOMSchemaService> schemaService) {
this(schemaService, "rests");
}
- protected BaseYangSwaggerGeneratorRFC8040(final Optional<DOMSchemaService> schemaService, final String basePath) {
+ protected BaseYangOpenApiGeneratorRFC8040(final Optional<DOMSchemaService> schemaService, final String basePath) {
super(schemaService);
this.basePath = requireNonNull(basePath);
}
*/
package org.opendaylight.netconf.sal.rest.doc.impl;
-import static org.opendaylight.netconf.sal.rest.doc.impl.BaseYangSwaggerGenerator.MODULE_NAME_SUFFIX;
+import static org.opendaylight.netconf.sal.rest.doc.impl.BaseYangOpenApiGenerator.MODULE_NAME_SUFFIX;
import static org.opendaylight.netconf.sal.rest.doc.model.builder.OperationBuilder.COMPONENTS_PREFIX;
import static org.opendaylight.netconf.sal.rest.doc.model.builder.OperationBuilder.CONFIG;
import static org.opendaylight.netconf.sal.rest.doc.model.builder.OperationBuilder.NAME_KEY;
import java.util.Optional;
import org.opendaylight.mdsal.dom.api.DOMMountPointService;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.netconf.sal.rest.doc.mountpoints.MountPointSwagger;
+import org.opendaylight.netconf.sal.rest.doc.mountpoints.MountPointOpenApi;
/**
* MountPoint generator implementation for RFC 8040.
*
* @author Thomas Pantelis
*/
-public class MountPointSwaggerGeneratorRFC8040 extends BaseYangSwaggerGeneratorRFC8040 implements AutoCloseable {
- private final MountPointSwagger mountPointSwagger;
+public class MountPointOpenApiGeneratorRFC8040 extends BaseYangOpenApiGeneratorRFC8040 implements AutoCloseable {
+ private final MountPointOpenApi mountPointOpenApi;
- public MountPointSwaggerGeneratorRFC8040(final DOMSchemaService schemaService,
+ public MountPointOpenApiGeneratorRFC8040(final DOMSchemaService schemaService,
final DOMMountPointService mountService) {
super(Optional.of(schemaService));
- mountPointSwagger = new MountPointSwagger(schemaService, mountService, this);
- mountPointSwagger.init();
+ mountPointOpenApi = new MountPointOpenApi(schemaService, mountService, this);
+ mountPointOpenApi.init();
}
- public MountPointSwaggerGeneratorRFC8040(final DOMSchemaService schemaService,
+ public MountPointOpenApiGeneratorRFC8040(final DOMSchemaService schemaService,
final DOMMountPointService mountService, final String basePath) {
super(Optional.of(schemaService), basePath);
- mountPointSwagger = new MountPointSwagger(schemaService, mountService, this);
- mountPointSwagger.init();
+ mountPointOpenApi = new MountPointOpenApi(schemaService, mountService, this);
+ mountPointOpenApi.init();
}
- public MountPointSwagger getMountPointSwagger() {
- return mountPointSwagger;
+ public MountPointOpenApi getMountPointOpenApi() {
+ return mountPointOpenApi;
}
@Override
public void close() {
- mountPointSwagger.close();
+ mountPointOpenApi.close();
}
}
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
import static org.opendaylight.netconf.sal.rest.doc.impl.ApiDocServiceImpl.DEFAULT_PAGESIZE;
-import static org.opendaylight.netconf.sal.rest.doc.impl.BaseYangSwaggerGenerator.BASE_PATH;
+import static org.opendaylight.netconf.sal.rest.doc.impl.BaseYangOpenApiGenerator.BASE_PATH;
import static org.opendaylight.netconf.sal.rest.doc.model.builder.OperationBuilder.DESCRIPTION_KEY;
import static org.opendaylight.netconf.sal.rest.doc.model.builder.OperationBuilder.RESPONSES_KEY;
import static org.opendaylight.netconf.sal.rest.doc.model.builder.OperationBuilder.SUMMARY_KEY;
import org.opendaylight.mdsal.dom.api.DOMMountPointListener;
import org.opendaylight.mdsal.dom.api.DOMMountPointService;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.netconf.sal.rest.doc.impl.BaseYangSwaggerGenerator;
+import org.opendaylight.netconf.sal.rest.doc.impl.BaseYangOpenApiGenerator;
import org.opendaylight.netconf.sal.rest.doc.impl.DefinitionNames;
import org.opendaylight.netconf.sal.rest.doc.openapi.CommonApiObject;
import org.opendaylight.netconf.sal.rest.doc.openapi.SwaggerObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class MountPointSwagger implements DOMMountPointListener, AutoCloseable {
+public class MountPointOpenApi implements DOMMountPointListener, AutoCloseable {
- private static final Logger LOG = LoggerFactory.getLogger(MountPointSwagger.class);
+ private static final Logger LOG = LoggerFactory.getLogger(MountPointOpenApi.class);
private static final String DATASTORES_REVISION = "-";
private static final String DATASTORES_LABEL = "Datastores";
private final DOMSchemaService globalSchema;
private final DOMMountPointService mountService;
- private final BaseYangSwaggerGenerator swaggerGenerator;
+ private final BaseYangOpenApiGenerator openApiGenerator;
private final Map<YangInstanceIdentifier, Long> instanceIdToLongId =
new TreeMap<>((o1, o2) -> o1.toString().compareToIgnoreCase(o2.toString()));
private final Map<Long, YangInstanceIdentifier> longIdToInstanceId = new HashMap<>();
private ListenerRegistration<DOMMountPointListener> registration;
- public MountPointSwagger(final DOMSchemaService globalSchema, final DOMMountPointService mountService,
- final BaseYangSwaggerGenerator swaggerGenerator) {
+ public MountPointOpenApi(final DOMSchemaService globalSchema, final DOMMountPointService mountService,
+ final BaseYangOpenApiGenerator openApiGenerator) {
this.globalSchema = requireNonNull(globalSchema);
this.mountService = requireNonNull(mountService);
- this.swaggerGenerator = requireNonNull(swaggerGenerator);
+ this.openApiGenerator = requireNonNull(openApiGenerator);
}
public void init() {
final SchemaContext context = globalSchema.getGlobalContext();
for (final Entry<YangInstanceIdentifier, Long> entry : instanceIdToLongId.entrySet()) {
final String modName = findModuleName(entry.getKey(), context);
- urlToId.put(swaggerGenerator.generateUrlPrefixFromInstanceID(entry.getKey(), modName),
+ urlToId.put(openApiGenerator.generateUrlPrefixFromInstanceID(entry.getKey(), modName),
entry.getValue());
}
}
private String getYangMountUrl(final YangInstanceIdentifier key) {
final String modName = findModuleName(key, globalSchema.getGlobalContext());
- return swaggerGenerator.generateUrlPrefixFromInstanceID(key, modName) + "yang-ext:mount";
+ return openApiGenerator.generateUrlPrefixFromInstanceID(key, modName) + "yang-ext:mount";
}
private YangInstanceIdentifier getInstanceId(final Long id) {
if (DATASTORES_LABEL.equals(module) && DATASTORES_REVISION.equals(revision)) {
return generateDataStoreApiDoc(uriInfo, urlPrefix, deviceName);
}
- final SwaggerObject swaggerObject = swaggerGenerator.getApiDeclaration(module, revision, uriInfo, context,
+ final SwaggerObject swaggerObject = openApiGenerator.getApiDeclaration(module, revision, uriInfo, context,
urlPrefix);
- return BaseYangSwaggerGenerator.convertToOpenApi(swaggerObject);
+ return BaseYangOpenApiGenerator.convertToOpenApi(swaggerObject);
}
public CommonApiObject getMountPointApi(final UriInfo uriInfo, final Long id, final Optional<Integer> pageNum) {
final SwaggerObject doc;
- final SwaggerObject swaggerObject = swaggerGenerator.getAllModulesDoc(uriInfo, range, context,
+ final SwaggerObject swaggerObject = openApiGenerator.getAllModulesDoc(uriInfo, range, context,
Optional.of(deviceName), urlPrefix, definitionNames);
if (includeDataStore) {
doc = swaggerObject;
}
- return BaseYangSwaggerGenerator.convertToOpenApi(doc);
+ return BaseYangOpenApiGenerator.convertToOpenApi(doc);
}
private static String extractDeviceName(final YangInstanceIdentifier iid) {
private SwaggerObject generateDataStoreApiDoc(final UriInfo uriInfo, final String context,
final String deviceName) {
- final SwaggerObject declaration = swaggerGenerator.createSwaggerObject(
- swaggerGenerator.createSchemaFromUriInfo(uriInfo),
- swaggerGenerator.createHostFromUriInfo(uriInfo),
+ final SwaggerObject declaration = openApiGenerator.createSwaggerObject(
+ openApiGenerator.createSchemaFromUriInfo(uriInfo),
+ openApiGenerator.createHostFromUriInfo(uriInfo),
BASE_PATH,
context);
final ObjectNode responses = JsonNodeFactory.instance.objectNode();
responses.set(String.valueOf(Response.Status.OK.getStatusCode()), okResponse);
operationObject.set(RESPONSES_KEY, responses);
- pathsObject.set(swaggerGenerator.getResourcePath(resourceType, context), pathItem);
+ pathsObject.set(openApiGenerator.getResourcePath(resourceType, context), pathItem);
}
@Override
final DOMMountPointService service = mock(DOMMountPointService.class);
when(service.getMountPoint(INSTANCE_ID)).thenReturn(Optional.of(mountPoint));
- final MountPointSwaggerGeneratorRFC8040 mountPointRFC8040 =
- new MountPointSwaggerGeneratorRFC8040(SCHEMA_SERVICE, service);
+ final MountPointOpenApiGeneratorRFC8040 mountPointRFC8040 =
+ new MountPointOpenApiGeneratorRFC8040(SCHEMA_SERVICE, service);
final ApiDocGeneratorRFC8040 apiDocGeneratorRFC8040 = new ApiDocGeneratorRFC8040(SCHEMA_SERVICE);
- mountPointRFC8040.getMountPointSwagger().onMountPointCreated(INSTANCE_ID);
+ mountPointRFC8040.getMountPointOpenApi().onMountPointCreated(INSTANCE_ID);
apiDocService = new ApiDocServiceImpl(mountPointRFC8040, apiDocGeneratorRFC8040);
}
import org.opendaylight.mdsal.dom.api.DOMMountPoint;
import org.opendaylight.mdsal.dom.api.DOMMountPointService;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.netconf.sal.rest.doc.mountpoints.MountPointSwagger;
+import org.opendaylight.netconf.sal.rest.doc.mountpoints.MountPointOpenApi;
import org.opendaylight.netconf.sal.rest.doc.openapi.SwaggerObject;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-public final class MountPointSwaggerTest extends AbstractApiDocTest {
+public final class MountPointOpenApiTest extends AbstractApiDocTest {
private static final String HTTP_URL = "http://localhost/path";
private static final YangInstanceIdentifier INSTANCE_ID = YangInstanceIdentifier.builder()
.node(QName.create("", "nodes"))
.nodeWithKey(QName.create("", "node"), QName.create("", "id"), "123").build();
private static final String INSTANCE_URL = "/nodes/node=123/";
- private MountPointSwagger swagger;
+ private MountPointOpenApi openApi;
@Before
public void before() {
final DOMMountPointService service = mock(DOMMountPointService.class);
when(service.getMountPoint(INSTANCE_ID)).thenReturn(Optional.of(mountPoint));
- swagger = new MountPointSwaggerGeneratorRFC8040(SCHEMA_SERVICE, service).getMountPointSwagger();
+ openApi = new MountPointOpenApiGeneratorRFC8040(SCHEMA_SERVICE, service).getMountPointOpenApi();
}
@Test()
public void getInstanceIdentifiers() {
- assertEquals(0, swagger.getInstanceIdentifiers().size());
- swagger.onMountPointCreated(INSTANCE_ID); // add this ID into the list of mount points
- assertEquals(1, swagger.getInstanceIdentifiers().size());
- assertEquals((Long) 1L, swagger.getInstanceIdentifiers().entrySet().iterator().next()
+ assertEquals(0, openApi.getInstanceIdentifiers().size());
+ openApi.onMountPointCreated(INSTANCE_ID); // add this ID into the list of mount points
+ assertEquals(1, openApi.getInstanceIdentifiers().size());
+ assertEquals((Long) 1L, openApi.getInstanceIdentifiers().entrySet().iterator().next()
.getValue());
- assertEquals(INSTANCE_URL, swagger.getInstanceIdentifiers().entrySet().iterator().next()
+ assertEquals(INSTANCE_URL, openApi.getInstanceIdentifiers().entrySet().iterator().next()
.getKey());
- swagger.onMountPointRemoved(INSTANCE_ID); // remove ID from list of mount points
- assertEquals(0, swagger.getInstanceIdentifiers().size());
+ openApi.onMountPointRemoved(INSTANCE_ID); // remove ID from list of mount points
+ assertEquals(0, openApi.getInstanceIdentifiers().size());
}
@Test
public void testGetDataStoreApi() throws Exception {
final UriInfo mockInfo = DocGenTestHelper.createMockUriInfo(HTTP_URL);
- swagger.onMountPointCreated(INSTANCE_ID); // add this ID into the list of mount points
+ openApi.onMountPointCreated(INSTANCE_ID); // add this ID into the list of mount points
- final SwaggerObject mountPointApi = (SwaggerObject) swagger.getMountPointApi(mockInfo, 1L, "Datastores", "-");
+ final SwaggerObject mountPointApi = (SwaggerObject) openApi.getMountPointApi(mockInfo, 1L, "Datastores", "-");
assertNotNull("failed to find Datastore API", mountPointApi);
final ObjectNode pathsObject = mountPointApi.getPaths();