Skip to content

Commit

Permalink
feat(schemaFormat): support OpenAPI 3.0.1, 3.0.2, 3.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Pakisan committed Apr 12, 2024
1 parent 38b8219 commit fc65b73
Show file tree
Hide file tree
Showing 23 changed files with 2,586 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@
@JsonSubTypes.Type(value = OpenAPIFormatSchema.class, names = {
"application/vnd.oai.openapi;version=3.0.0",
"application/vnd.oai.openapi+json;version=3.0.0",
"application/vnd.oai.openapi+yaml;version=3.0.0"
"application/vnd.oai.openapi+yaml;version=3.0.0",
"application/vnd.oai.openapi;version=3.0.1",
"application/vnd.oai.openapi+json;version=3.0.1",
"application/vnd.oai.openapi+yaml;version=3.0.1",
"application/vnd.oai.openapi;version=3.0.2",
"application/vnd.oai.openapi+json;version=3.0.2",
"application/vnd.oai.openapi+yaml;version=3.0.2",
"application/vnd.oai.openapi;version=3.0.3",
"application/vnd.oai.openapi+json;version=3.0.3",
"application/vnd.oai.openapi+yaml;version=3.0.3"
}),
@JsonSubTypes.Type(value = AsyncAPIFormatSchema.class, names = {
"application/vnd.aai.asyncapi;version=2.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import com.asyncapi.v3.ClasspathUtils
import com.asyncapi.v3.schema.SchemaProvider
import com.asyncapi.v3.schema.json.*
import com.asyncapi.v3.schema.openapi.SchemaTest
import com.asyncapi.v3.schema.multiformat.openapi.OpenAPIFormatSchemaV3_0_0Test
import com.asyncapi.v3.schema.multiformat.openapi.OpenAPIFormatSchemaV3_0_1Test
import com.asyncapi.v3.schema.multiformat.openapi.OpenAPIFormatSchemaV3_0_2Test
import com.asyncapi.v3.schema.multiformat.openapi.OpenAPIFormatSchemaV3_0_3Test
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
Expand Down Expand Up @@ -257,17 +261,21 @@ class MultiFormatSchemaTest {
@Nested
inner class OpenAPISchema {

@ArgumentsSource(OpenAPISchemasJsonFormat::class)
@ParameterizedTest(name = "Read: {0}")
fun json(schemaToCompareWith: String, schemaProvider: SchemaProvider) {
compareSchemas(schemaToCompareWith, OpenAPIFormatSchema::class.java, schemaProvider.openAPIFormatSchemaJson())
}
@Nested
@DisplayName("3.0.0")
inner class V3_0_0: OpenAPIFormatSchemaV3_0_0Test()

@ArgumentsSource(OpenAPISchemasYamlFormat::class)
@ParameterizedTest(name = "Read: {0}")
fun yaml(schemaToCompareWith: String, schemaProvider: SchemaProvider) {
compareSchemas(schemaToCompareWith, OpenAPIFormatSchema::class.java, schemaProvider.openAPIFormatSchemaYaml())
}
@Nested
@DisplayName("3.0.1")
inner class V3_0_1: OpenAPIFormatSchemaV3_0_1Test()

@Nested
@DisplayName("3.0.2")
inner class V3_0_2: OpenAPIFormatSchemaV3_0_2Test()

@Nested
@DisplayName("3.0.3")
inner class V3_0_3: OpenAPIFormatSchemaV3_0_3Test()

}

Expand Down Expand Up @@ -559,26 +567,6 @@ class MultiFormatSchemaTest {

}

class OpenAPISchemasJsonFormat: ArgumentsProvider {

override fun provideArguments(context: ExtensionContext?): Stream<out Arguments> {
return Stream.of(
Arguments.of("/json/v3/schema/multiformat/openapi/schema.json", SchemaTest()),
)
}

}

class OpenAPISchemasYamlFormat: ArgumentsProvider {

override fun provideArguments(context: ExtensionContext?): Stream<out Arguments> {
return Stream.of(
Arguments.of("/json/v3/schema/multiformat/openapi/schema.yaml", SchemaTest()),
)
}

}

class JsonSchemasWithEmptySchemaFormat: ArgumentsProvider {

override fun provideArguments(context: ExtensionContext?): Stream<out Arguments> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.asyncapi.v3.schema.multiformat.openapi

import com.asyncapi.v3.ClasspathUtils
import com.asyncapi.v3.schema.multiformat.OpenAPIFormatSchema
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import org.junit.jupiter.api.Assertions

abstract class OpenAPIFormatSchemaTest {

private val objectMapper: ObjectMapper = ObjectMapper(YAMLFactory())
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.findAndRegisterModules()

fun compareSchemas(
openAPIFormatSchemaToCompareWithFilePath: String,
schemaToCheck: OpenAPIFormatSchema
) {
val schemaAsJson = ClasspathUtils.readAsString(openAPIFormatSchemaToCompareWithFilePath)
val schema = objectMapper.readValue(schemaAsJson, OpenAPIFormatSchema::class.java)

Assertions.assertEquals(schema, schemaToCheck)
}

abstract fun parseJson(
openAPIFormatSchemaToCompareWithFilePath: String,
openAPIFormatSchema: OpenAPIFormatSchema
)

abstract fun parseYaml(
openAPIFormatSchemaToCompareWithFilePath: String,
openAPIFormatSchema: OpenAPIFormatSchema
)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.asyncapi.v3.schema.multiformat.openapi

import com.asyncapi.v3.schema.multiformat.OpenAPIFormatSchema
import com.asyncapi.v3.schema.openapi.SchemaTest
import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.ArgumentsProvider
import org.junit.jupiter.params.provider.ArgumentsSource
import java.util.stream.Stream

abstract class OpenAPIFormatSchemaV3_0_0Test: OpenAPIFormatSchemaTest() {

@ArgumentsSource(JsonFormat::class)
@ParameterizedTest(name = "Read: {0}")
override fun parseJson(
openAPIFormatSchemaToCompareWithFilePath: String,
openAPIFormatSchema: OpenAPIFormatSchema
) {
compareSchemas(openAPIFormatSchemaToCompareWithFilePath, openAPIFormatSchema)
}

@ArgumentsSource(YamlFormat::class)
@ParameterizedTest(name = "Read: {0}")
override fun parseYaml(
openAPIFormatSchemaToCompareWithFilePath: String,
openAPIFormatSchema: OpenAPIFormatSchema
) {
compareSchemas(openAPIFormatSchemaToCompareWithFilePath, openAPIFormatSchema)
}

class JsonFormat: ArgumentsProvider {

override fun provideArguments(context: ExtensionContext?): Stream<out Arguments> {
return Stream.of(
Arguments.of("/json/v3/schema/multiformat/openapi/3.0.0/vnd.oai.openapi/schema.json",
OpenAPIFormatSchema("application/vnd.oai.openapi;version=3.0.0", SchemaTest().openAPISchema())
),
Arguments.of("/json/v3/schema/multiformat/openapi/3.0.0/vnd.oai.openapi+json/schema.json",
OpenAPIFormatSchema("application/vnd.oai.openapi+json;version=3.0.0", SchemaTest().openAPISchema())
)
)
}

}

class YamlFormat: ArgumentsProvider {

override fun provideArguments(context: ExtensionContext?): Stream<out Arguments> {
return Stream.of(
Arguments.of("/json/v3/schema/multiformat/openapi/3.0.0/vnd.oai.openapi/schema.yaml",
OpenAPIFormatSchema("application/vnd.oai.openapi;version=3.0.0", SchemaTest().openAPISchema())
),
Arguments.of("/json/v3/schema/multiformat/openapi/3.0.0/vnd.oai.openapi+yaml/schema.yaml",
OpenAPIFormatSchema("application/vnd.oai.openapi+yaml;version=3.0.0", SchemaTest().openAPISchema())
)
)
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.asyncapi.v3.schema.multiformat.openapi

import com.asyncapi.v3.schema.multiformat.OpenAPIFormatSchema
import com.asyncapi.v3.schema.multiformat.openapi.OpenAPIFormatSchemaV3_0_0Test.JsonFormat
import com.asyncapi.v3.schema.multiformat.openapi.OpenAPIFormatSchemaV3_0_0Test.YamlFormat
import com.asyncapi.v3.schema.openapi.SchemaTest
import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.ArgumentsProvider
import org.junit.jupiter.params.provider.ArgumentsSource
import java.util.stream.Stream

abstract class OpenAPIFormatSchemaV3_0_1Test: OpenAPIFormatSchemaTest() {

@ArgumentsSource(JsonFormat::class)
@ParameterizedTest(name = "Read: {0}")
override fun parseJson(
openAPIFormatSchemaToCompareWithFilePath: String,
openAPIFormatSchema: OpenAPIFormatSchema
) {
compareSchemas(openAPIFormatSchemaToCompareWithFilePath, openAPIFormatSchema)
}

@ArgumentsSource(YamlFormat::class)
@ParameterizedTest(name = "Read: {0}")
override fun parseYaml(
openAPIFormatSchemaToCompareWithFilePath: String,
openAPIFormatSchema: OpenAPIFormatSchema
) {
compareSchemas(openAPIFormatSchemaToCompareWithFilePath, openAPIFormatSchema)
}

class JsonFormat: ArgumentsProvider {

override fun provideArguments(context: ExtensionContext?): Stream<out Arguments> {
return Stream.of(
Arguments.of("/json/v3/schema/multiformat/openapi/3.0.1/vnd.oai.openapi/schema.json",
OpenAPIFormatSchema("application/vnd.oai.openapi;version=3.0.1", SchemaTest().openAPISchema())
),
Arguments.of("/json/v3/schema/multiformat/openapi/3.0.1/vnd.oai.openapi+json/schema.json",
OpenAPIFormatSchema("application/vnd.oai.openapi+json;version=3.0.1", SchemaTest().openAPISchema())
)
)
}

}

class YamlFormat: ArgumentsProvider {

override fun provideArguments(context: ExtensionContext?): Stream<out Arguments> {
return Stream.of(
Arguments.of("/json/v3/schema/multiformat/openapi/3.0.1/vnd.oai.openapi/schema.yaml",
OpenAPIFormatSchema("application/vnd.oai.openapi;version=3.0.1", SchemaTest().openAPISchema())
),
Arguments.of("/json/v3/schema/multiformat/openapi/3.0.1/vnd.oai.openapi+yaml/schema.yaml",
OpenAPIFormatSchema("application/vnd.oai.openapi+yaml;version=3.0.1", SchemaTest().openAPISchema())
)
)
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.asyncapi.v3.schema.multiformat.openapi

import com.asyncapi.v3.schema.multiformat.OpenAPIFormatSchema
import com.asyncapi.v3.schema.multiformat.openapi.OpenAPIFormatSchemaV3_0_0Test.JsonFormat
import com.asyncapi.v3.schema.multiformat.openapi.OpenAPIFormatSchemaV3_0_0Test.YamlFormat
import com.asyncapi.v3.schema.openapi.SchemaTest
import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.ArgumentsProvider
import org.junit.jupiter.params.provider.ArgumentsSource
import java.util.stream.Stream

abstract class OpenAPIFormatSchemaV3_0_2Test: OpenAPIFormatSchemaTest() {

@ArgumentsSource(JsonFormat::class)
@ParameterizedTest(name = "Read: {0}")
override fun parseJson(
openAPIFormatSchemaToCompareWithFilePath: String,
openAPIFormatSchema: OpenAPIFormatSchema
) {
compareSchemas(openAPIFormatSchemaToCompareWithFilePath, openAPIFormatSchema)
}

@ArgumentsSource(YamlFormat::class)
@ParameterizedTest(name = "Read: {0}")
override fun parseYaml(
openAPIFormatSchemaToCompareWithFilePath: String,
openAPIFormatSchema: OpenAPIFormatSchema
) {
compareSchemas(openAPIFormatSchemaToCompareWithFilePath, openAPIFormatSchema)
}

class JsonFormat: ArgumentsProvider {

override fun provideArguments(context: ExtensionContext?): Stream<out Arguments> {
return Stream.of(
Arguments.of("/json/v3/schema/multiformat/openapi/3.0.2/vnd.oai.openapi/schema.json",
OpenAPIFormatSchema("application/vnd.oai.openapi;version=3.0.2", SchemaTest().openAPISchema())
),
Arguments.of("/json/v3/schema/multiformat/openapi/3.0.2/vnd.oai.openapi+json/schema.json",
OpenAPIFormatSchema("application/vnd.oai.openapi+json;version=3.0.2", SchemaTest().openAPISchema())
)
)
}

}

class YamlFormat: ArgumentsProvider {

override fun provideArguments(context: ExtensionContext?): Stream<out Arguments> {
return Stream.of(
Arguments.of("/json/v3/schema/multiformat/openapi/3.0.2/vnd.oai.openapi/schema.yaml",
OpenAPIFormatSchema("application/vnd.oai.openapi;version=3.0.2", SchemaTest().openAPISchema())
),
Arguments.of("/json/v3/schema/multiformat/openapi/3.0.2/vnd.oai.openapi+yaml/schema.yaml",
OpenAPIFormatSchema("application/vnd.oai.openapi+yaml;version=3.0.2", SchemaTest().openAPISchema())
)
)
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.asyncapi.v3.schema.multiformat.openapi

import com.asyncapi.v3.schema.multiformat.OpenAPIFormatSchema
import com.asyncapi.v3.schema.multiformat.openapi.OpenAPIFormatSchemaV3_0_0Test.JsonFormat
import com.asyncapi.v3.schema.multiformat.openapi.OpenAPIFormatSchemaV3_0_0Test.YamlFormat
import com.asyncapi.v3.schema.openapi.SchemaTest
import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.ArgumentsProvider
import org.junit.jupiter.params.provider.ArgumentsSource
import java.util.stream.Stream

abstract class OpenAPIFormatSchemaV3_0_3Test: OpenAPIFormatSchemaTest() {

@ArgumentsSource(JsonFormat::class)
@ParameterizedTest(name = "Read: {0}")
override fun parseJson(
openAPIFormatSchemaToCompareWithFilePath: String,
openAPIFormatSchema: OpenAPIFormatSchema
) {
compareSchemas(openAPIFormatSchemaToCompareWithFilePath, openAPIFormatSchema)
}

@ArgumentsSource(YamlFormat::class)
@ParameterizedTest(name = "Read: {0}")
override fun parseYaml(
openAPIFormatSchemaToCompareWithFilePath: String,
openAPIFormatSchema: OpenAPIFormatSchema
) {
compareSchemas(openAPIFormatSchemaToCompareWithFilePath, openAPIFormatSchema)
}

class JsonFormat: ArgumentsProvider {

override fun provideArguments(context: ExtensionContext?): Stream<out Arguments> {
return Stream.of(
Arguments.of("/json/v3/schema/multiformat/openapi/3.0.3/vnd.oai.openapi/schema.json",
OpenAPIFormatSchema("application/vnd.oai.openapi;version=3.0.3", SchemaTest().openAPISchema())
),
Arguments.of("/json/v3/schema/multiformat/openapi/3.0.3/vnd.oai.openapi+json/schema.json",
OpenAPIFormatSchema("application/vnd.oai.openapi+json;version=3.0.3", SchemaTest().openAPISchema())
)
)
}

}

class YamlFormat: ArgumentsProvider {

override fun provideArguments(context: ExtensionContext?): Stream<out Arguments> {
return Stream.of(
Arguments.of("/json/v3/schema/multiformat/openapi/3.0.3/vnd.oai.openapi/schema.yaml",
OpenAPIFormatSchema("application/vnd.oai.openapi;version=3.0.3", SchemaTest().openAPISchema())
),
Arguments.of("/json/v3/schema/multiformat/openapi/3.0.3/vnd.oai.openapi+yaml/schema.yaml",
OpenAPIFormatSchema("application/vnd.oai.openapi+yaml;version=3.0.3", SchemaTest().openAPISchema())
)
)
}

}

}
Loading

0 comments on commit fc65b73

Please sign in to comment.