From e928cfe48fe7716ba439b54dd223ea78594317a3 Mon Sep 17 00:00:00 2001 From: Jerre van Veluw Date: Tue, 12 Nov 2024 19:57:47 +0100 Subject: [PATCH] refactor: emit identifier (#285) --- .../maven/custom/emit/CustomEmitter.java | 11 +- .../compiler/core/emit/JavaEmitter.kt | 56 +++--- .../compiler/core/emit/KotlinEmitter.kt | 47 ++--- .../compiler/core/emit/ScalaEmitter.kt | 22 +-- .../compiler/core/emit/TypeScriptEmitter.kt | 43 ++--- .../compiler/core/emit/WirespecEmitter.kt | 31 ++-- .../compiler/core/emit/common/Emitter.kt | 7 +- .../compiler/core/emit/common/Emitters.kt | 2 +- .../compiler/core/parse/ChannelParser.kt | 4 +- .../compiler/core/parse/EndpointParser.kt | 6 +- .../compiler/core/parse/EnumParser.kt | 4 +- .../wirespec/compiler/core/parse/Node.kt | 42 ++--- .../compiler/core/parse/TypeParser.kt | 10 +- .../compiler/core/fixture/NodeFixtures.kt | 17 +- .../compiler/core/parse/ParseEndpointTest.kt | 2 +- .../flock/wirespec/compiler/lib/Ast.kt | 38 ++-- .../wirespec/openapi/v2/OpenApiV2Parser.kt | 23 +-- .../wirespec/openapi/v3/OpenApiV3Parser.kt | 23 +-- .../flock/wirespec/openapi/common/Expected.kt | 129 +++++++------- .../openapi/v2/OpenApiV2ParserTest.kt | 79 ++++----- .../openapi/v3/OpenApiV3ParserTest.kt | 163 +++++++++--------- 21 files changed, 385 insertions(+), 374 deletions(-) diff --git a/examples/maven-spring-custom/emitter/src/main/java/community/flock/wirespec/example/maven/custom/emit/CustomEmitter.java b/examples/maven-spring-custom/emitter/src/main/java/community/flock/wirespec/example/maven/custom/emit/CustomEmitter.java index b956b195..cb8bef9b 100644 --- a/examples/maven-spring-custom/emitter/src/main/java/community/flock/wirespec/example/maven/custom/emit/CustomEmitter.java +++ b/examples/maven-spring-custom/emitter/src/main/java/community/flock/wirespec/example/maven/custom/emit/CustomEmitter.java @@ -8,6 +8,7 @@ import community.flock.wirespec.compiler.core.parse.Endpoint; import community.flock.wirespec.compiler.core.parse.Enum; import community.flock.wirespec.compiler.core.parse.Field; +import community.flock.wirespec.compiler.core.parse.Identifier; import community.flock.wirespec.compiler.core.parse.Node; import community.flock.wirespec.compiler.core.parse.Reference; import community.flock.wirespec.compiler.core.parse.Refined; @@ -27,7 +28,7 @@ public CustomEmitter(@NotNull Logger logger, boolean split) { @NotNull @Override public String emitName(@NotNull Definition definition) { - return definition.getIdentifier() + "Custom"; + return emit(definition.getIdentifier()) + "Custom"; } @NotNull @@ -67,7 +68,7 @@ public String emit(@NotNull Enum anEnum) { @NotNull @Override - public String emit(@NotNull Union aUnion) { + public String emit(@NotNull Union union) { return notYetImplemented(); } @@ -106,4 +107,10 @@ public String emit(@NotNull Field field) { public String emit(@NotNull Reference reference) { return notYetImplemented(); } + + @NotNull + @Override + public String emit(@NotNull Identifier identifier) { + return identifier.getValue(); + } } diff --git a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/JavaEmitter.kt b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/JavaEmitter.kt index 99aea8dd..f3c09c6a 100644 --- a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/JavaEmitter.kt +++ b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/JavaEmitter.kt @@ -12,11 +12,12 @@ import community.flock.wirespec.compiler.core.orNull import community.flock.wirespec.compiler.core.parse.AST import community.flock.wirespec.compiler.core.parse.Channel import community.flock.wirespec.compiler.core.parse.Definition +import community.flock.wirespec.compiler.core.parse.DefinitionIdentifier import community.flock.wirespec.compiler.core.parse.Endpoint import community.flock.wirespec.compiler.core.parse.Enum import community.flock.wirespec.compiler.core.parse.Field +import community.flock.wirespec.compiler.core.parse.FieldIdentifier import community.flock.wirespec.compiler.core.parse.Identifier -import community.flock.wirespec.compiler.core.parse.Identifier.Type.* import community.flock.wirespec.compiler.core.parse.Reference import community.flock.wirespec.compiler.core.parse.Refined import community.flock.wirespec.compiler.core.parse.Type @@ -36,12 +37,12 @@ open class JavaEmitter( """.trimMargin() override fun Definition.emitName(): String = when (this) { - is Endpoint -> "${identifier.emit(Class)}Endpoint" - is Channel -> "${identifier.emit(Class)}Channel" - is Enum -> identifier.emit(Class) - is Refined -> identifier.emit(Class) - is Type -> identifier.emit(Class) - is Union -> identifier.emit(Class) + is Endpoint -> "${emit(identifier)}Endpoint" + is Channel -> "${emit(identifier)}Channel" + is Enum -> emit(identifier) + is Refined -> emit(identifier) + is Type -> emit(identifier) + is Union -> emit(identifier) } override fun notYetImplemented() = @@ -80,7 +81,7 @@ open class JavaEmitter( override fun Type.Shape.emit() = value.joinToString("\n") { "${Spacer}${it.emit()}," }.dropLast(1) override fun Field.emit() = - "${if (isNullable) "java.util.Optional<${reference.emit()}>" else reference.emit()} ${identifier.emit(Field)}" + "${if (isNullable) "java.util.Optional<${reference.emit()}>" else reference.emit()} ${emit(identifier)}" override fun Reference.emit() = emitType() .let { if (isIterable) "java.util.List<$it>" else it } @@ -107,13 +108,13 @@ open class JavaEmitter( Reference.Primitive.Type.Boolean -> "Boolean" } - override fun Identifier.emit(type: Identifier.Type) = when (type) { - Class -> value.sanitizeSymbol().firstToUpper() - Field -> value.sanitizeSymbol().firstToLower().sanitizeKeywords() + override fun emit(identifier: Identifier) = when (identifier) { + is DefinitionIdentifier -> identifier.value.sanitizeSymbol().firstToUpper() + is FieldIdentifier -> identifier.value.sanitizeSymbol().firstToLower().sanitizeKeywords() } override fun emit(refined: Refined) = """ - |public record ${refined.identifier.emit(Class)} (String value) implements Wirespec.Refined { + |public record ${emit(refined.identifier)} (String value) implements Wirespec.Refined { |${Spacer}@Override |${Spacer}public String toString() { return value; } |${Spacer}public static boolean validate(${refined.emitName()} record) { @@ -129,10 +130,10 @@ open class JavaEmitter( """${Spacer}return java.util.regex.Pattern.compile("${expression.replace("\\", "\\\\")}").matcher(record.value).find();""" override fun emit(enum: Enum) = """ - |public enum ${enum.identifier.emit(Class)} implements Wirespec.Enum { + |public enum ${emit(enum.identifier)} implements Wirespec.Enum { |${enum.entries.joinToString(",\n") { "${it.sanitizeEnum().sanitizeKeywords()}(\"$it\")" }.spacer()}; |${Spacer}public final String label; - |${Spacer}${enum.identifier.emit(Class)}(String label) { + |${Spacer}${emit(enum.identifier)}(String label) { |${Spacer(2)}this.label = label; |${Spacer}} |${Spacer}@Override @@ -153,14 +154,14 @@ open class JavaEmitter( """.trimMargin() override fun emit(channel: Channel) = """ - |interface ${channel.identifier.emit(Class)}Channel { + |interface ${emit(channel.identifier)}Channel { | void invoke(${channel.reference.emitWrap(channel.isNullable)} message) |} | """.trimMargin() override fun emit(endpoint: Endpoint) = """ - |public interface ${endpoint.identifier.emit(Class)}Endpoint extends Wirespec.Endpoint { + |public interface ${emit(endpoint.identifier)}Endpoint extends Wirespec.Endpoint { |${endpoint.pathParams.emitObject("Path", "Wirespec.Path") { it.emit() }} | |${endpoint.queries.emitObject("Queries", "Wirespec.Queries") { it.emit() }} @@ -214,7 +215,7 @@ open class JavaEmitter( """.trimMargin() open fun emitHandleFunction(endpoint: Endpoint) = - "java.util.concurrent.CompletableFuture> ${endpoint.identifier.emit(Field)}(Request request);" + "java.util.concurrent.CompletableFuture> ${emit(endpoint.identifier).firstToLower()}(Request request);" private fun Endpoint.emitStatusInterfaces() = responses .map { it.status.first() } @@ -274,7 +275,7 @@ open class JavaEmitter( ).joinToString() }) implements Response${status.first()}XX<${content.emit()}>, Response${content.emit().concatGenerics()} { |${Spacer(2)}@Override public int getStatus() { return ${status.fixStatus()}; } - |${Spacer(2)}${headers.joinToString { it.identifier.emit(Field) }.let { "@Override public Headers getHeaders() { return new Headers($it); }" }} + |${Spacer(2)}${headers.joinToString { emit(it.identifier) }.let { "@Override public Headers getHeaders() { return new Headers($it); }" }} |${Spacer(2)}@Override public ${content.emit()} getBody() { return ${if(content == null) "null" else "body"}; } |${Spacer(1)}${headers.emitObject("Headers", "Wirespec.Response.Headers") { it.emit() }} |${Spacer}} @@ -290,10 +291,10 @@ open class JavaEmitter( ).joinToString() }) {\n${Spacer(3)}${ listOfNotNull( - endpoint.pathParams.joinToString { it.identifier.emit(Field) }.let { "this.path = new Path($it);" }, + endpoint.pathParams.joinToString { emit(it.identifier) }.let { "this.path = new Path($it);" }, "this.method = Wirespec.Method.${endpoint.method.name};", - endpoint.queries.joinToString { it.identifier.emit(Field) }.let { "this.queries = new Queries($it);" }, - endpoint.headers.joinToString { it.identifier.emit(Field) } + endpoint.queries.joinToString { emit(it.identifier) }.let { "this.queries = new Queries($it);" }, + endpoint.headers.joinToString { emit(it.identifier) } .let { "this.headers = new RequestHeaders($it);" }, "this.body = ${content?.let { "body" } ?: "null"};" ).joinToString("\n${Spacer(3)}") @@ -318,7 +319,7 @@ open class JavaEmitter( """${Spacer(4)}case $status -> new Response${status.firstToUpper()}(${this.emitDeserializedParams()});""" private fun Field.emitSerialized(fields: String) = - """java.util.Map.entry("${identifier.value}", serialization.serialize(request.$fields.${identifier.emit(Field)}, Wirespec.getType(${reference.emitType()}.class, ${reference.isIterable})))""" + """java.util.Map.entry("${identifier.value}", serialization.serialize(request.$fields.${emit(identifier)}, Wirespec.getType(${reference.emitType()}.class, ${reference.isIterable})))""" private fun IndexedValue.emitDeserialized() = """${Spacer(4)}serialization.<${value.reference.emit()}>deserialize(request.path().get(${index}), Wirespec.getType(${value.reference.emitType()}.class, ${value.reference.isIterable}))""" @@ -327,21 +328,20 @@ open class JavaEmitter( """${Spacer(4)}java.util.Optional.ofNullable(request.$fields().get("${identifier.value}")).map(it -> serialization.<${reference.emit()}>deserialize(it, Wirespec.getType(${reference.emitType()}.class, ${reference.isIterable})))${if(!isNullable) ".get()" else ""}""" private fun Field.emitSerializedMap(fields: String) = - """java.util.Map.entry("${identifier.value}", serialization.serialize(response.$fields.${identifier.emit(Field)}, Wirespec.getType(${reference.emitType()}.class, ${reference.isIterable})))""" + """java.util.Map.entry("${identifier.value}", serialization.serialize(response.$fields.${emit(identifier)}, Wirespec.getType(${reference.emitType()}.class, ${reference.isIterable})))""" - private fun Endpoint.Segment.Param.emitIdentifier() = "serialization.serialize(request.path.${identifier.emit(Field).firstToLower()}, Wirespec.getType(${reference.emitType()}.class, ${reference.isIterable}))" + private fun Endpoint.Segment.Param.emitIdentifier() = "serialization.serialize(request.path.${emit(identifier).firstToLower()}, Wirespec.getType(${reference.emitType()}.class, ${reference.isIterable}))" private fun Endpoint.Content?.emitType() = this?.reference?.emitType() ?: "Void" private fun Endpoint.Content?.emit() = this?.reference?.emit() ?: "Void" - private fun Endpoint.Segment.Param.emit() = "${reference.emit()} ${identifier.emit(Field)}" + private fun Endpoint.Segment.Param.emit() = "${reference.emit()} ${emit(identifier)}" private fun Reference.emitWrap(isNullable: Boolean): String = value - .let { if (isIterable) "java.util.Optional<$it>" else it } - .let { if (isNullable) "java.util.List<$it>" else it } + .let { if (isNullable) "java.util.Optional<$it>" else it } + .let { if (isIterable) "java.util.List<$it>" else it } .let { if (isDictionary) "java.util.Map" else it } - private fun String.fixStatus(): String = when (this) { "default" -> "200" else -> this diff --git a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/KotlinEmitter.kt b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/KotlinEmitter.kt index 64fe11e7..e74219c3 100644 --- a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/KotlinEmitter.kt +++ b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/KotlinEmitter.kt @@ -13,11 +13,12 @@ import community.flock.wirespec.compiler.core.orNull import community.flock.wirespec.compiler.core.parse.AST import community.flock.wirespec.compiler.core.parse.Channel import community.flock.wirespec.compiler.core.parse.Definition +import community.flock.wirespec.compiler.core.parse.DefinitionIdentifier import community.flock.wirespec.compiler.core.parse.Endpoint import community.flock.wirespec.compiler.core.parse.Enum import community.flock.wirespec.compiler.core.parse.Field +import community.flock.wirespec.compiler.core.parse.FieldIdentifier import community.flock.wirespec.compiler.core.parse.Identifier -import community.flock.wirespec.compiler.core.parse.Identifier.Type.* import community.flock.wirespec.compiler.core.parse.Reference import community.flock.wirespec.compiler.core.parse.Refined import community.flock.wirespec.compiler.core.parse.Type @@ -38,12 +39,12 @@ open class KotlinEmitter( """.trimMargin() override fun Definition.emitName(): String = when (this) { - is Endpoint -> "${identifier.emit(Class)}Endpoint" - is Channel -> "${identifier.emit(Class)}Channel" - is Enum -> identifier.emit(Class) - is Refined -> identifier.emit(Class) - is Type -> identifier.emit(Class) - is Union -> identifier.emit(Class) + is Endpoint -> "${emit(identifier)}Endpoint" + is Channel -> "${emit(identifier)}Channel" + is Enum -> emit(identifier) + is Refined -> emit(identifier) + is Type -> emit(identifier) + is Union -> emit(identifier) } override fun notYetImplemented() = @@ -74,7 +75,7 @@ open class KotlinEmitter( override fun Type.Shape.emit() = value.joinToString("\n") { "${Spacer}val ${it.emit()}," }.dropLast(1) - override fun Field.emit() = "${identifier.emit(Field)}: ${reference.emit()}${if (isNullable) "?" else ""}" + override fun Field.emit() = "${emit(identifier)}: ${reference.emit()}${if (isNullable) "?" else ""}" override fun Reference.emit() = when (this) { is Reference.Unit -> "Unit" @@ -90,9 +91,9 @@ open class KotlinEmitter( .let { if (isIterable) "List<$it>" else it } .let { if (isDictionary) "Map" else it } - override fun Identifier.emit(type: Identifier.Type) = when(type){ - Class -> value.sanitizeSymbol().firstToUpper() - Field -> value.sanitizeSymbol().firstToLower().sanitizeKeywords() + override fun emit(identifier: Identifier) = when (identifier) { + is DefinitionIdentifier -> identifier.value.sanitizeSymbol().firstToUpper() + is FieldIdentifier -> identifier.value.sanitizeSymbol().firstToLower().sanitizeKeywords() } override fun emit(refined: Refined) = """ @@ -122,14 +123,14 @@ open class KotlinEmitter( """.trimMargin() override fun emit(channel: Channel) = """ - |interface ${channel.identifier.emit(Class)}Channel { + |interface ${emit(channel.identifier)}Channel { | operator fun invoke(message: ${channel.reference.emitWrap(channel.isNullable)}) |} | """.trimMargin() override fun emit(endpoint: Endpoint) = """ - |object ${endpoint.identifier.emit(Class)}Endpoint : Wirespec.Endpoint { + |object ${emit(endpoint.identifier)}Endpoint : Wirespec.Endpoint { |${endpoint.pathParams.emitObject("Path", "Wirespec.Path") { it.emit() }} | |${endpoint.queries.emitObject("Queries", "Wirespec.Queries") { it.emit() }} @@ -177,7 +178,7 @@ open class KotlinEmitter( """.trimMargin() open fun emitHandleFunction(endpoint: Endpoint): String = - "suspend fun ${endpoint.identifier.emit(Class).firstToLower()}(request: Request): Response<*>" + "suspend fun ${emit(endpoint.identifier).firstToLower()}(request: Request): Response<*>" private fun Endpoint.emitStatusInterfaces() = responses .map { it.status[0] } @@ -199,10 +200,10 @@ open class KotlinEmitter( fun Endpoint.Request.emit(endpoint: Endpoint) = """ |${Spacer}${emitConstructor(endpoint)} - |${Spacer(2)}override val path = Path${endpoint.pathParams.joinToString { it.identifier.emit(Field) }.brace()} + |${Spacer(2)}override val path = Path${endpoint.pathParams.joinToString { emit(it.identifier) }.brace()} |${Spacer(2)}override val method = Wirespec.Method.${endpoint.method.name} - |${Spacer(2)}override val queries = Queries${endpoint.queries.joinToString { it.identifier.emit(Field) }.brace()} - |${Spacer(2)}override val headers = Headers${endpoint.headers.joinToString { it.identifier.emit(Field) }.brace()}${if (content == null) "\n${Spacer(2)}override val body = Unit" else ""} + |${Spacer(2)}override val queries = Queries${endpoint.queries.joinToString { emit(it.identifier) }.brace()} + |${Spacer(2)}override val headers = Headers${endpoint.headers.joinToString { emit(it.identifier) }.brace()}${if (content == null) "\n${Spacer(2)}override val body = Unit" else ""} |${Spacer}} | |${Spacer}fun toRequest(serialization: Wirespec.Serializer, request: Request): Wirespec.RawRequest = @@ -256,23 +257,23 @@ open class KotlinEmitter( """.trimMargin() private fun Field.emitSerialized(fields: String) = - """request.$fields.${identifier.emit(Field)}?.let{"${identifier.value}" to serialization.serialize(it, typeOf<${reference.emit()}>())}""" + """request.$fields.${emit(identifier)}?.let{"${identifier.value}" to serialization.serialize(it, typeOf<${reference.emit()}>())}""" private fun IndexedValue.emitDeserialized() = - """${Spacer(3)}${value.identifier.emit(Field)} = serialization.deserialize(request.path[${index}], typeOf<${value.reference.emit()}>())""" + """${Spacer(3)}${emit(value.identifier)} = serialization.deserialize(request.path[${index}], typeOf<${value.reference.emit()}>())""" private fun Field.emitDeserialized(fields: String) = if (isNullable) - """${Spacer(3)}${identifier.emit(Field)} = request.$fields["${identifier.value}"]?.let{ serialization.deserialize(it, typeOf<${reference.emit()}>()) }""" + """${Spacer(3)}${emit(identifier)} = request.$fields["${identifier.value}"]?.let{ serialization.deserialize(it, typeOf<${reference.emit()}>()) }""" else - """${Spacer(3)}${identifier.emit(Field)} = serialization.deserialize(requireNotNull(request.$fields["${identifier.value}"]) { "${identifier.emit(Field)} is null" }, typeOf<${reference.emit()}>())""" + """${Spacer(3)}${emit(identifier)} = serialization.deserialize(requireNotNull(request.$fields["${identifier.value}"]) { "${emit(identifier)} is null" }, typeOf<${reference.emit()}>())""" private fun Endpoint.Segment.Param.emitIdentifier() = - "request.path.${identifier.emit(Field)}.let{serialization.serialize(it, typeOf<${reference.emit()}>())}" + "request.path.${emit(identifier)}.let{serialization.serialize(it, typeOf<${reference.emit()}>())}" private fun Endpoint.Content?.emit() = this?.reference?.emit() ?: "Unit" - private fun Endpoint.Segment.Param.emit() = "${identifier.emit(Field)}: ${reference.emit()}" + private fun Endpoint.Segment.Param.emit() = "${emit(identifier)}: ${reference.emit()}" private fun String.brace() = wrap("(", ")") private fun String.wrap(prefix: String, postfix: String) = if (isEmpty()) "" else "$prefix$this$postfix" diff --git a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/ScalaEmitter.kt b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/ScalaEmitter.kt index ca0929fb..e4e5edd9 100644 --- a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/ScalaEmitter.kt +++ b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/ScalaEmitter.kt @@ -15,7 +15,6 @@ import community.flock.wirespec.compiler.core.parse.Endpoint import community.flock.wirespec.compiler.core.parse.Enum import community.flock.wirespec.compiler.core.parse.Field import community.flock.wirespec.compiler.core.parse.Identifier -import community.flock.wirespec.compiler.core.parse.Identifier.Type.* import community.flock.wirespec.compiler.core.parse.Reference import community.flock.wirespec.compiler.core.parse.Refined import community.flock.wirespec.compiler.core.parse.Type @@ -35,12 +34,12 @@ open class ScalaEmitter( """.trimMargin() override fun Definition.emitName(): String = when (this) { - is Endpoint -> "${identifier.emit(Class)}Endpoint" - is Channel -> "${identifier.emit(Class)}Channel" - is Enum -> identifier.emit(Class) - is Refined -> identifier.emit(Class) - is Type -> identifier.emit(Class) - is Union -> identifier.emit(Class) + is Endpoint -> "${emit(identifier)}Endpoint" + is Channel -> "${emit(identifier)}Channel" + is Enum -> emit(identifier) + is Refined -> emit(identifier) + is Type -> emit(identifier) + is Union -> emit(identifier) } override fun notYetImplemented() = @@ -70,9 +69,10 @@ open class ScalaEmitter( override fun Type.Shape.emit() = value.joinToString("\n") { it.emit() }.dropLast(1) override fun Field.emit() = - "${Spacer}val ${identifier.emit(Field)}: ${if (isNullable) "Option[${reference.emit()}]" else reference.emit()}," + "${Spacer}val ${emit(identifier)}: ${if (isNullable) "Option[${reference.emit()}]" else reference.emit()}," - override fun Identifier.emit(type: Identifier.Type) = if (value in reservedKeywords) value.addBackticks() else value + override fun emit(identifier: Identifier) = + identifier.run { if (value in reservedKeywords) value.addBackticks() else value } override fun emit(channel: Channel) = notYetImplemented() @@ -94,8 +94,8 @@ open class ScalaEmitter( fun String.sanitize() = replace("-", "_").let { if (it.first().isDigit()) "_$it" else it } """ |sealed abstract class ${emitName()}(val label: String) - |object ${identifier.emit(Class)} { - |${entries.joinToString("\n") { """${Spacer}final case object ${it.sanitize().uppercase()} extends ${identifier.emit(Class)}(label = "$it")""" }} + |object ${emit(identifier)} { + |${entries.joinToString("\n") { """${Spacer}final case object ${it.sanitize().uppercase()} extends ${emit(identifier)}(label = "$it")""" }} |} |""".trimMargin() } diff --git a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/TypeScriptEmitter.kt b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/TypeScriptEmitter.kt index 08df29f2..69fcb2a1 100644 --- a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/TypeScriptEmitter.kt +++ b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/TypeScriptEmitter.kt @@ -12,7 +12,6 @@ import community.flock.wirespec.compiler.core.parse.Endpoint import community.flock.wirespec.compiler.core.parse.Enum import community.flock.wirespec.compiler.core.parse.Field import community.flock.wirespec.compiler.core.parse.Identifier -import community.flock.wirespec.compiler.core.parse.Identifier.Type.* import community.flock.wirespec.compiler.core.parse.Reference import community.flock.wirespec.compiler.core.parse.Refined import community.flock.wirespec.compiler.core.parse.Type @@ -23,12 +22,12 @@ import community.flock.wirespec.compiler.utils.noLogger open class TypeScriptEmitter(logger: Logger = noLogger) : DefinitionModelEmitter, Emitter(logger) { override fun Definition.emitName(): String = when (this) { - is Endpoint -> identifier.emit(Class) - is Enum -> identifier.emit(Class) - is Refined -> identifier.emit(Class) - is Type -> identifier.emit(Class) - is Union -> identifier.emit(Class) - is Channel -> identifier.emit(Class) + is Endpoint -> emit(identifier) + is Enum -> emit(identifier) + is Refined -> emit(identifier) + is Type -> emit(identifier) + is Union -> emit(identifier) + is Channel -> emit(identifier) } override fun notYetImplemented() = @@ -59,10 +58,10 @@ open class TypeScriptEmitter(logger: Logger = noLogger) : DefinitionModelEmitter override fun Type.Shape.emit() = value.joinToString(",\n") { it.emit() } internal fun Endpoint.Segment.Param.emit() = - "${Spacer}\"${identifier.emit(Field)}\": ${reference.emit()}" + "${Spacer}\"${emit(identifier)}\": ${reference.emit()}" override fun Field.emit() = - "${Spacer}\"${identifier.emit(Field)}\"${if (isNullable) "?" else ""}: ${reference.emit()}" + "${Spacer}\"${emit(identifier)}\"${if (isNullable) "?" else ""}: ${reference.emit()}" override fun Reference.emit() = when (this) { is Reference.Unit -> "void" @@ -80,9 +79,9 @@ open class TypeScriptEmitter(logger: Logger = noLogger) : DefinitionModelEmitter override fun emit(refined: Refined) = """export type ${refined.identifier.sanitizeSymbol()} = string; - |const regExp${refined.identifier.emit(Class)} = ${refined.validator.emit()}; - |export const validate${refined.identifier.emit(Class)} = (value: string): value is ${refined.identifier.sanitizeSymbol()} => - |${Spacer}regExp${refined.identifier.emit(Class)}.test(value); + |const regExp${emit(refined.identifier)} = ${refined.validator.emit()}; + |export const validate${emit(refined.identifier)} = (value: string): value is ${refined.identifier.sanitizeSymbol()} => + |${Spacer}regExp${emit(refined.identifier)}.test(value); |""".trimMargin() override fun Refined.Validator.emit() = value @@ -113,6 +112,8 @@ open class TypeScriptEmitter(logger: Logger = noLogger) : DefinitionModelEmitter override fun emit(union: Union) = "export type ${union.identifier.sanitizeSymbol()} = ${union.entries.joinToString(" | ") { it.emit() }}\n" + override fun emit(identifier: Identifier) = identifier.value + override fun emit(channel: Channel) = notYetImplemented() private fun List.emitType(name: String, block: (E) -> String) = @@ -138,10 +139,10 @@ open class TypeScriptEmitter(logger: Logger = noLogger) : DefinitionModelEmitter private fun Endpoint.Request.emitFunction(endpoint: Endpoint) = """ |${Spacer}export const request = (${paramList(endpoint).takeIf { it.isNotEmpty() }?.let { "props: ${it.joinToObject { it.emit() }}" }.orEmpty()}): Request => ({ - |${Spacer(2)}path: ${endpoint.pathParams.joinToObject { "${it.identifier.emit(Field)}: props.${it.identifier.emit(Field)}" }}, + |${Spacer(2)}path: ${endpoint.pathParams.joinToObject { "${emit(it.identifier)}: props.${emit(it.identifier)}" }}, |${Spacer(2)}method: "${endpoint.method}", - |${Spacer(2)}queries: ${endpoint.queries.joinToObject { "${it.identifier.emit(Field)}: props.${it.identifier.emit(Field)}" }}, - |${Spacer(2)}headers: ${endpoint.headers.joinToObject { "${it.identifier.emit(Field)}: props.${it.identifier.emit(Field)}" }}, + |${Spacer(2)}queries: ${endpoint.queries.joinToObject { "${emit(it.identifier)}: props.${emit(it.identifier)}" }}, + |${Spacer(2)}headers: ${endpoint.headers.joinToObject { "${emit(it.identifier)}: props.${emit(it.identifier)}" }}, |${Spacer(2)}body: ${content?.let { "props.body" } ?: "undefined"}, |${Spacer}}) """.trimIndent() @@ -149,7 +150,7 @@ open class TypeScriptEmitter(logger: Logger = noLogger) : DefinitionModelEmitter private fun Endpoint.Response.emitFunction(endpoint: Endpoint) = """ |${Spacer}export const response${status.firstToUpper()} = (${paramList().takeIf { it.isNotEmpty() }?.let { "props: ${it.joinToObject { it.emit() }}" }.orEmpty()}): Response${status.firstToUpper()} => ({ |${Spacer(2)}status: ${status}, - |${Spacer(2)}headers: ${endpoint.headers.joinToObject { "${it.identifier.emit(Field)}: props.${it.identifier.emit(Field)}" }}, + |${Spacer(2)}headers: ${endpoint.headers.joinToObject { "${emit(it.identifier)}: props.${emit(it.identifier)}" }}, |${Spacer(2)}body: ${content?.let { "props.body" } ?: "undefined"}, |${Spacer}}) """.trimIndent() @@ -157,7 +158,7 @@ open class TypeScriptEmitter(logger: Logger = noLogger) : DefinitionModelEmitter private fun Iterable.joinToObject(transform: ((T) -> CharSequence)) = joinToString(", ", "{", "}", transform = transform) - private fun Param.emit() = "${identifier.emit(Field)}${if (isNullable) "?" else ""}: ${reference.emit()}" + private fun Param.emit() = "${emit(identifier)}${if (isNullable) "?" else ""}: ${reference.emit()}" private fun Endpoint.Response.emitName() = "Response" + status.firstToUpper() @@ -187,7 +188,7 @@ open class TypeScriptEmitter(logger: Logger = noLogger) : DefinitionModelEmitter private fun Endpoint.emitPathArray() = path.joinToString(", ", "[", "]") { when (it) { is Endpoint.Segment.Literal -> """"${it.value}"""" - is Endpoint.Segment.Param -> "serialization.serialize(request.path.${it.identifier})" + is Endpoint.Segment.Param -> "serialization.serialize(request.path.${emit(it.identifier)})" } } @@ -254,11 +255,11 @@ open class TypeScriptEmitter(logger: Logger = noLogger) : DefinitionModelEmitter """.trimMargin() private fun IndexedValue.emitDeserialize() = - """${value.identifier.emit(Field)}: serialization.deserialize(request.path[${index}])""" + """${emit(value.identifier)}: serialization.deserialize(request.path[${index}])""" private fun Field.emitDeserialize(fields: String) = - """${identifier.emit(Field)}: serialization.deserialize(request.$fields.${identifier.emit(Field)})""" + """${emit(identifier)}: serialization.deserialize(request.$fields.${emit(identifier)})""" private fun Field.emitSerialize(fields: String) = - """${identifier.emit(Field)}: serialization.serialize(request.$fields.${identifier.emit(Field)})""" + """${emit(identifier)}: serialization.serialize(request.$fields.${emit(identifier)})""" } diff --git a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/WirespecEmitter.kt b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/WirespecEmitter.kt index b4fd9d9d..2832c26c 100644 --- a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/WirespecEmitter.kt +++ b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/WirespecEmitter.kt @@ -12,7 +12,6 @@ import community.flock.wirespec.compiler.core.parse.Endpoint import community.flock.wirespec.compiler.core.parse.Enum import community.flock.wirespec.compiler.core.parse.Field import community.flock.wirespec.compiler.core.parse.Identifier -import community.flock.wirespec.compiler.core.parse.Identifier.Type.* import community.flock.wirespec.compiler.core.parse.Reference import community.flock.wirespec.compiler.core.parse.Refined import community.flock.wirespec.compiler.core.parse.Type @@ -23,29 +22,31 @@ import community.flock.wirespec.compiler.utils.noLogger open class WirespecEmitter(logger: Logger = noLogger) : DefinitionModelEmitter, Emitter(logger) { override fun Definition.emitName(): String = when (this) { - is Endpoint -> identifier.emit(Class) - is Enum -> identifier.emit(Class) - is Refined -> identifier.emit(Class) - is Type -> identifier.emit(Class) - is Union -> identifier.emit(Class) - is Channel -> identifier.emit(Class) + is Endpoint -> emit(identifier) + is Enum -> emit(identifier) + is Refined -> emit(identifier) + is Type -> emit(identifier) + is Union -> emit(identifier) + is Channel -> emit(identifier) } override fun notYetImplemented() = "\n" override fun emit(type: Type, ast: AST) = """ - |type ${type.identifier.emit(Class)} { + |type ${emit(type.identifier)} { |${type.shape.emit()} |} |""".trimMargin() override fun Type.Shape.emit() = value.joinToString(",\n") { "$Spacer${it.emit()}" } - override fun Field.emit() = "${identifier.emit(Field)}: ${reference.emit()}${if (isNullable) "?" else ""}" + override fun Field.emit() = "${emit(identifier)}: ${reference.emit()}${if (isNullable) "?" else ""}" - override fun Identifier.emit(type: Identifier.Type) = if (value in reservedKeywords) value.addBackticks() else value + override fun emit(identifier: Identifier) = + identifier.run { if (value in reservedKeywords) value.addBackticks() else value } - override fun emit(channel: Channel): String = "channel ${channel.identifier.emit(Class)} -> ${channel.reference.emit()}" + override fun emit(channel: Channel): String = + "channel ${emit(channel.identifier)} -> ${channel.reference.emit()}" override fun Reference.emit(): String = when (this) { is Reference.Unit -> "Unit" @@ -62,21 +63,21 @@ open class WirespecEmitter(logger: Logger = noLogger) : DefinitionModelEmitter, .let { if (isDictionary) "{ $it }" else it } override fun emit(enum: Enum) = - "enum ${enum.identifier.emit(Class)} {\n${Spacer}${enum.entries.joinToString(", ") { it.capitalize() }}\n}\n" + "enum ${emit(enum.identifier)} {\n${Spacer}${enum.entries.joinToString(", ") { it.capitalize() }}\n}\n" - override fun emit(refined: Refined) = "type ${refined.identifier.emit(Class)} ${refined.validator.emit()}\n" + override fun emit(refined: Refined) = "type ${emit(refined.identifier)} ${refined.validator.emit()}\n" override fun Refined.Validator.emit() = value override fun emit(endpoint: Endpoint) = """ - |endpoint ${endpoint.identifier.emit(Class)} ${endpoint.method}${endpoint.requests.emitRequest()} ${endpoint.path.emitPath()}${endpoint.queries.emitQuery()} -> { + |endpoint ${emit(endpoint.identifier)} ${endpoint.method}${endpoint.requests.emitRequest()} ${endpoint.path.emitPath()}${endpoint.queries.emitQuery()} -> { |${endpoint.responses.joinToString("\n") { "$Spacer${it.status.fixStatus()} -> ${it.content?.reference?.emit() ?: "Unit"}${if (it.content?.isNullable == true) "?" else ""}" }} |} | """.trimMargin() override fun emit(union: Union) = - "type ${union.identifier.emit(Class)} = ${union.entries.joinToString(" | ") { it.emit() }}\n" + "type ${emit(union.identifier)} = ${union.entries.joinToString(" | ") { it.emit() }}\n" private fun String.fixStatus(): String = when (this) { "default" -> "200" diff --git a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/common/Emitter.kt b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/common/Emitter.kt index a0788d46..ec913795 100644 --- a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/common/Emitter.kt +++ b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/common/Emitter.kt @@ -7,8 +7,8 @@ import community.flock.wirespec.compiler.core.parse.Definition import community.flock.wirespec.compiler.core.parse.Endpoint import community.flock.wirespec.compiler.core.parse.Enum import community.flock.wirespec.compiler.core.parse.Field +import community.flock.wirespec.compiler.core.parse.FieldIdentifier import community.flock.wirespec.compiler.core.parse.Identifier -import community.flock.wirespec.compiler.core.parse.Identifier.Type.Class import community.flock.wirespec.compiler.core.parse.Reference import community.flock.wirespec.compiler.core.parse.Refined import community.flock.wirespec.compiler.core.parse.Type @@ -70,7 +70,7 @@ abstract class Emitter( internal fun Endpoint.Segment.emitMap() = when (this) { is Endpoint.Segment.Literal -> value - is Endpoint.Segment.Param -> "${'$'}{props.${identifier.emit(Class)}}" + is Endpoint.Segment.Param -> "${'$'}{props.${emit(identifier)}}" } internal val Endpoint.pathParams get() = path.filterIsInstance() @@ -104,7 +104,7 @@ abstract class Emitter( private fun Endpoint.Content.toParam() = Param( type = ParamType.BODY, - identifier = Identifier("body"), + identifier = FieldIdentifier("body"), reference = reference, isNullable = isNullable ) @@ -121,7 +121,6 @@ abstract class Emitter( fun String.firstToLower() = replaceFirstChar(Char::lowercase) fun AST.needImports() = any { it is Endpoint || it is Enum || it is Refined } fun AST.hasEndpoints() = any { it is Endpoint } - fun String.isInt() = toIntOrNull() != null fun String.isStatusCode() = toIntOrNull()?.let { it in 0..599 } ?: false val internalClasses = setOf( "Request", "Response" diff --git a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/common/Emitters.kt b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/common/Emitters.kt index 372558ef..dd4f5200 100644 --- a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/common/Emitters.kt +++ b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/emit/common/Emitters.kt @@ -43,5 +43,5 @@ interface ChannelDefinitionEmitter { } interface IdentifierEmitter { - fun Identifier.emit(type: Identifier.Type) = value + fun emit(identifier: Identifier): String } diff --git a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/parse/ChannelParser.kt b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/parse/ChannelParser.kt index 380ff948..4529bc5f 100644 --- a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/parse/ChannelParser.kt +++ b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/parse/ChannelParser.kt @@ -21,12 +21,12 @@ class ChannelParser(logger: Logger) : AbstractParser(logger) { eatToken().bind() token.log() when (token.type) { - is CustomType -> parseChannelDefinition(comment, Identifier(token.value)).bind() + is CustomType -> parseChannelDefinition(comment, DefinitionIdentifier(token.value)).bind() else -> raise(WrongTokenException(token).also { eatToken().bind() }) } } - private fun TokenProvider.parseChannelDefinition(comment: Comment?, identifier: Identifier) = either { + private fun TokenProvider.parseChannelDefinition(comment: Comment?, identifier: DefinitionIdentifier) = either { eatToken().bind() when (token.type) { diff --git a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/parse/EndpointParser.kt b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/parse/EndpointParser.kt index f44ace83..b16b7117 100644 --- a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/parse/EndpointParser.kt +++ b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/parse/EndpointParser.kt @@ -33,12 +33,12 @@ class EndpointParser(logger: Logger) : AbstractParser(logger) { eatToken().bind() token.log() when (token.type) { - is CustomType -> parseEndpointDefinition(comment, Identifier(token.value)).bind() + is CustomType -> parseEndpointDefinition(comment, DefinitionIdentifier(token.value)).bind() else -> raise(WrongTokenException(token).also { eatToken().bind() }) } } - private fun TokenProvider.parseEndpointDefinition(comment: Comment?, name: Identifier) = either { + private fun TokenProvider.parseEndpointDefinition(comment: Comment?, name: DefinitionIdentifier) = either { eatToken().bind() token.log() val method = when (token.type) { @@ -149,7 +149,7 @@ class EndpointParser(logger: Logger) : AbstractParser(logger) { else -> raise(WrongTokenException(token)) } val identifier = when (token.type) { - is CustomValue -> Identifier(token.value).also { eatToken().bind() } + is CustomValue -> FieldIdentifier(token.value).also { eatToken().bind() } else -> raise(WrongTokenException(token)) } when (token.type) { diff --git a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/parse/EnumParser.kt b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/parse/EnumParser.kt index f45fc876..809fbf73 100644 --- a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/parse/EnumParser.kt +++ b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/parse/EnumParser.kt @@ -16,12 +16,12 @@ class EnumParser(logger: Logger) : AbstractParser(logger) { eatToken().bind() token.log() when (token.type) { - is CustomType -> parseEnumTypeDefinition(comment, Identifier(token.value)).bind() + is CustomType -> parseEnumTypeDefinition(comment, DefinitionIdentifier(token.value)).bind() else -> raise(WrongTokenException(token).also { eatToken().bind() }) } } - private fun TokenProvider.parseEnumTypeDefinition(comment: Comment?, typeName: Identifier) = either { + private fun TokenProvider.parseEnumTypeDefinition(comment: Comment?, typeName: DefinitionIdentifier) = either { eatToken().bind() token.log() when (token.type) { diff --git a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/parse/Node.kt b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/parse/Node.kt index 70cc67c9..94b386bc 100644 --- a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/parse/Node.kt +++ b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/parse/Node.kt @@ -13,7 +13,7 @@ sealed interface Definition : Node { data class Type( override val comment: Comment?, - override val identifier: Identifier, + override val identifier: DefinitionIdentifier, val shape: Shape, val extends: List, ) : Definition { @@ -55,23 +55,23 @@ sealed interface Reference : Value { } } -data class Field(val identifier: Identifier, val reference: Reference, val isNullable: Boolean) +data class Field(val identifier: FieldIdentifier, val reference: Reference, val isNullable: Boolean) data class Enum( override val comment: Comment?, - override val identifier: Identifier, + override val identifier: DefinitionIdentifier, val entries: Set, ) : Definition data class Union( override val comment: Comment?, - override val identifier: Identifier, + override val identifier: DefinitionIdentifier, val entries: Set, ) : Definition data class Refined( override val comment: Comment?, - override val identifier: Identifier, + override val identifier: DefinitionIdentifier, val validator: Validator, ) : Definition { data class Validator(override val value: String) : Value { @@ -81,7 +81,7 @@ data class Refined( data class Endpoint( override val comment: Comment?, - override val identifier: Identifier, + override val identifier: DefinitionIdentifier, val method: Method, val path: List, val queries: List, @@ -94,7 +94,7 @@ data class Endpoint( sealed interface Segment { data class Literal(override val value: String) : Value, Segment data class Param( - val identifier: Identifier, + val identifier: FieldIdentifier, val reference: Reference ) : Segment } @@ -106,7 +106,7 @@ data class Endpoint( data class Channel( override val comment: Comment?, - override val identifier: Identifier, + override val identifier: DefinitionIdentifier, val isNullable: Boolean, val reference: Reference, ) : Definition @@ -114,26 +114,10 @@ data class Channel( @JvmInline value class Comment(override val value: String) : Value -class Identifier private constructor(override val value: String) : Value { - - enum class Type { Class, Field } - - override fun toString(): String = value - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || this::class != other::class) return false - - other as Identifier - - return value == other.value - } +sealed class Identifier(name: String) : Value { + override val value = name.removeBackticks() +} - override fun hashCode(): Int = value.hashCode() +data class DefinitionIdentifier(private val name: String) : Identifier(name) - companion object { - operator fun invoke(value: String) = value - .removeBackticks() - .let(::Identifier) - } -} +data class FieldIdentifier(private val name: String) : Identifier(name) diff --git a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/parse/TypeParser.kt b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/parse/TypeParser.kt index b671e7ae..60b68a74 100644 --- a/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/parse/TypeParser.kt +++ b/src/compiler/core/src/commonMain/kotlin/community/flock/wirespec/compiler/core/parse/TypeParser.kt @@ -32,7 +32,7 @@ class TypeParser(logger: Logger) : AbstractParser(logger) { eatToken().bind() token.log() when (token.type) { - is CustomType -> parseTypeDefinition(comment, Identifier(token.value)).bind() + is CustomType -> parseTypeDefinition(comment, DefinitionIdentifier(token.value)).bind() else -> raise(WrongTokenException(token).also { eatToken().bind() }) } } @@ -42,11 +42,11 @@ class TypeParser(logger: Logger) : AbstractParser(logger) { token.log() when (token.type) { is CustomValue -> mutableListOf().apply { - add(parseField(Identifier(token.value)).bind()) + add(parseField(FieldIdentifier(token.value)).bind()) while (token.type == Comma) { eatToken().bind() when (token.type) { - is CustomValue -> add(parseField(Identifier(token.value)).bind()) + is CustomValue -> add(parseField(FieldIdentifier(token.value)).bind()) else -> raise(WrongTokenException(token).also { eatToken().bind() }) } } @@ -117,7 +117,7 @@ class TypeParser(logger: Logger) : AbstractParser(logger) { } } - private fun TokenProvider.parseTypeDefinition(comment: Comment?, typeName: Identifier) = either { + private fun TokenProvider.parseTypeDefinition(comment: Comment?, typeName: DefinitionIdentifier) = either { eatToken().bind() token.log() when (token.type) { @@ -144,7 +144,7 @@ class TypeParser(logger: Logger) : AbstractParser(logger) { } } - private fun TokenProvider.parseField(identifier: Identifier) = either { + private fun TokenProvider.parseField(identifier: FieldIdentifier) = either { eatToken().bind() token.log() when (token.type) { diff --git a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/fixture/NodeFixtures.kt b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/fixture/NodeFixtures.kt index 5702a2ba..c7d7c778 100644 --- a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/fixture/NodeFixtures.kt +++ b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/fixture/NodeFixtures.kt @@ -1,8 +1,9 @@ package community.flock.wirespec.compiler.core.fixture +import community.flock.wirespec.compiler.core.parse.DefinitionIdentifier import community.flock.wirespec.compiler.core.parse.Enum import community.flock.wirespec.compiler.core.parse.Field -import community.flock.wirespec.compiler.core.parse.Identifier +import community.flock.wirespec.compiler.core.parse.FieldIdentifier import community.flock.wirespec.compiler.core.parse.Reference.Primitive import community.flock.wirespec.compiler.core.parse.Refined import community.flock.wirespec.compiler.core.parse.Type @@ -11,7 +12,7 @@ object NodeFixtures { val refined = Refined( comment = null, - identifier = Identifier("UUID"), + identifier = DefinitionIdentifier("UUID"), validator = Refined.Validator( "/^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}\$/" ) @@ -20,7 +21,7 @@ object NodeFixtures { val enum = Enum( comment = null, - identifier = Identifier("TodoStatus"), + identifier = DefinitionIdentifier("TodoStatus"), entries = setOf( "OPEN", "IN_PROGRESS", @@ -31,26 +32,26 @@ object NodeFixtures { val type = Type( comment = null, - identifier = Identifier("Todo"), + identifier = DefinitionIdentifier("Todo"), shape = Type.Shape( value = listOf( Field( - identifier = Identifier("name"), + identifier = FieldIdentifier("name"), reference = Primitive(type = Primitive.Type.String), isNullable = false, ), Field( - identifier = Identifier("description"), + identifier = FieldIdentifier("description"), reference = Primitive(type = Primitive.Type.String), isNullable = true, ), Field( - identifier = Identifier("notes"), + identifier = FieldIdentifier("notes"), reference = Primitive(type = Primitive.Type.String, isIterable = true), isNullable = false, ), Field( - identifier = Identifier("done"), + identifier = FieldIdentifier("done"), reference = Primitive(type = Primitive.Type.Boolean), isNullable = false, ) diff --git a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParseEndpointTest.kt b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParseEndpointTest.kt index 2b918dea..3be9bb66 100644 --- a/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParseEndpointTest.kt +++ b/src/compiler/core/src/commonTest/kotlin/community/flock/wirespec/compiler/core/parse/ParseEndpointTest.kt @@ -120,7 +120,7 @@ class ParseEndpointTest { method shouldBe GET path shouldBe listOf( Literal("todos"), Endpoint.Segment.Param( - identifier = Identifier("id"), + identifier = FieldIdentifier("id"), reference = Primitive( type = String, isIterable = false, diff --git a/src/compiler/lib/src/jsMain/kotlin/community/flock/wirespec/compiler/lib/Ast.kt b/src/compiler/lib/src/jsMain/kotlin/community/flock/wirespec/compiler/lib/Ast.kt index eb7ed927..69ae3fac 100644 --- a/src/compiler/lib/src/jsMain/kotlin/community/flock/wirespec/compiler/lib/Ast.kt +++ b/src/compiler/lib/src/jsMain/kotlin/community/flock/wirespec/compiler/lib/Ast.kt @@ -4,10 +4,11 @@ package community.flock.wirespec.compiler.lib import community.flock.wirespec.compiler.core.parse.Channel import community.flock.wirespec.compiler.core.parse.Comment +import community.flock.wirespec.compiler.core.parse.DefinitionIdentifier import community.flock.wirespec.compiler.core.parse.Endpoint import community.flock.wirespec.compiler.core.parse.Enum import community.flock.wirespec.compiler.core.parse.Field -import community.flock.wirespec.compiler.core.parse.Identifier +import community.flock.wirespec.compiler.core.parse.FieldIdentifier import community.flock.wirespec.compiler.core.parse.Node import community.flock.wirespec.compiler.core.parse.Reference import community.flock.wirespec.compiler.core.parse.Refined @@ -27,7 +28,7 @@ fun WsNode.consume(): Node = fun WsEndpoint.consume(): Endpoint = Endpoint( comment = comment?.let { Comment(it) }, - identifier = Identifier(identifier), + identifier = DefinitionIdentifier(identifier), method = method.consume(), path = path.map { it.consume() }, queries = query.map { it.consume() }, @@ -40,7 +41,10 @@ fun WsEndpoint.consume(): Endpoint = private fun WsSegment.consume() = when (this) { is WsLiteral -> Endpoint.Segment.Literal(value) - is WsParam -> Endpoint.Segment.Param(identifier.consume(), reference.consume()) + is WsParam -> Endpoint.Segment.Param( + identifier = identifier.consume(), + reference = reference.consume() + ) } private fun WsMethod.consume() = when (this) { @@ -54,35 +58,36 @@ private fun WsMethod.consume() = when (this) { WsMethod.TRACE -> Endpoint.Method.TRACE } -private fun WsIdentifier.consume() = Identifier(value) +private fun WsClassIdentifier.consume() = DefinitionIdentifier(value) +private fun WsFieldIdentifier.consume() = FieldIdentifier(value) private fun WsEnum.consume() = Enum( - identifier = Identifier(identifier), + identifier = DefinitionIdentifier(identifier), comment = comment?.let { Comment(it) }, entries = entries.toSet() ) private fun WsRefined.consume() = Refined( - identifier = Identifier(identifier), + identifier = DefinitionIdentifier(identifier), comment = comment?.let { Comment(it) }, validator = Refined.Validator(validator) ) private fun WsType.consume() = Type( - identifier = Identifier(identifier), + identifier = DefinitionIdentifier(identifier), comment = comment?.let { Comment(it) }, shape = Type.Shape(shape.value.map { it.consume() }), extends = emptyList(), ) private fun WsUnion.consume() = Union( - identifier = Identifier(identifier), + identifier = DefinitionIdentifier(identifier), comment = comment?.let { Comment(it) }, entries = entries.map { it.consume() }.toSet() ) private fun WsChannel.consume() = Channel( - identifier = Identifier(identifier), + identifier = DefinitionIdentifier(identifier), comment = comment?.let { Comment(it) }, reference = reference.consume(), isNullable = isNullable @@ -213,7 +218,8 @@ private fun Field.produce() = WsField(identifier.produce(), reference.produce(), private fun List.produce() = map { it.produce() }.toTypedArray() -private fun Identifier.produce() = WsIdentifier(value) +private fun DefinitionIdentifier.produce() = WsClassIdentifier(value) +private fun FieldIdentifier.produce() = WsFieldIdentifier(value) private fun Reference.produce() = when (this) { is Reference.Any -> WsAny(isIterable, isDictionary) @@ -322,7 +328,7 @@ data class WsLiteral(val value: String) : WsSegment @JsExport data class WsParam( - val identifier: WsIdentifier, + val identifier: WsFieldIdentifier, val reference: WsReference ) : WsSegment @@ -331,10 +337,16 @@ data class WsParam( data class Shape(val value: Array) @JsExport -data class WsField(val identifier: WsIdentifier, val reference: WsReference, val isNullable: Boolean) +data class WsField(val identifier: WsFieldIdentifier, val reference: WsReference, val isNullable: Boolean) + +@JsExport +sealed interface WsIdentifier + +@JsExport +data class WsClassIdentifier(val value: String) : WsIdentifier @JsExport -data class WsIdentifier(val value: String) +data class WsFieldIdentifier(val value: String) : WsIdentifier @JsExport sealed interface WsReference { diff --git a/src/converter/openapi/src/commonMain/kotlin/community/flock/wirespec/openapi/v2/OpenApiV2Parser.kt b/src/converter/openapi/src/commonMain/kotlin/community/flock/wirespec/openapi/v2/OpenApiV2Parser.kt index deaea6cf..bbc464dc 100644 --- a/src/converter/openapi/src/commonMain/kotlin/community/flock/wirespec/openapi/v2/OpenApiV2Parser.kt +++ b/src/converter/openapi/src/commonMain/kotlin/community/flock/wirespec/openapi/v2/OpenApiV2Parser.kt @@ -21,10 +21,11 @@ import community.flock.kotlinx.openapi.bindings.v2.StatusCode import community.flock.kotlinx.openapi.bindings.v2.SwaggerObject import community.flock.wirespec.compiler.core.parse.AST import community.flock.wirespec.compiler.core.parse.Definition +import community.flock.wirespec.compiler.core.parse.DefinitionIdentifier import community.flock.wirespec.compiler.core.parse.Endpoint import community.flock.wirespec.compiler.core.parse.Enum import community.flock.wirespec.compiler.core.parse.Field -import community.flock.wirespec.compiler.core.parse.Identifier +import community.flock.wirespec.compiler.core.parse.FieldIdentifier import community.flock.wirespec.compiler.core.parse.Reference import community.flock.wirespec.compiler.core.parse.Type import community.flock.wirespec.openapi.Common.className @@ -111,7 +112,7 @@ object OpenApiV2Parser { listOf( Endpoint( comment = null, - identifier = Identifier(name), + identifier = DefinitionIdentifier(name), method = method, path = segments, queries = query, @@ -143,7 +144,7 @@ object OpenApiV2Parser { parameter.enum != null -> listOf( Enum( comment = null, - identifier = Identifier(className(name, "Parameter", parameter.name)), + identifier = DefinitionIdentifier(className(name, "Parameter", parameter.name)), entries = parameter.enum!!.map { it.content }.toSet() ) ) @@ -280,7 +281,7 @@ object OpenApiV2Parser { schemaObject.allOf != null -> listOf( Type( comment = null, - identifier = Identifier(name), + identifier = DefinitionIdentifier(name), shape = Type.Shape(schemaObject.allOf .orEmpty() .flatMap { @@ -307,7 +308,7 @@ object OpenApiV2Parser { schemaObject.enum != null -> schemaObject.enum!! .map { it.content } .toSet() - .let { listOf(Enum(comment = null, identifier = Identifier(name), entries = it)) } + .let { listOf(Enum(comment = null, identifier = DefinitionIdentifier(name), entries = it)) } else -> when (schemaObject.type) { null, OpenapiType.OBJECT -> { @@ -317,7 +318,7 @@ object OpenApiV2Parser { val schema = listOf( Type( comment = null, - identifier = Identifier(name), + identifier = DefinitionIdentifier(name), shape = Type.Shape(toField(schemaObject, name)), extends = emptyList(), ) @@ -444,7 +445,7 @@ object OpenApiV2Parser { private fun SwaggerObject.toField(header: HeaderObject, identifier: String) = Field( - identifier = Identifier(identifier), + identifier = FieldIdentifier(identifier), reference = when (header.type) { "array" -> header.items?.let { resolve(it) }?.let { toReference(it, identifier) } ?: error("Item cannot be null") @@ -459,7 +460,7 @@ object OpenApiV2Parser { when (value) { is SchemaObject -> { Field( - identifier = Identifier(key), + identifier = FieldIdentifier(key), reference = when { value.enum != null -> toReference(value, className(name, key)) value.type == OpenapiType.ARRAY -> toReference(value, className(name, key, "Array")) @@ -471,7 +472,7 @@ object OpenApiV2Parser { is ReferenceObject -> { Field( - identifier = Identifier(key), + identifier = FieldIdentifier(key), reference = toReference(value), isNullable = !(schema.required?.contains(key) ?: false) ) @@ -500,7 +501,7 @@ object OpenApiV2Parser { } } - }.let { Field(Identifier(parameter.name), it, !(parameter.required ?: false)) } + }.let { Field(FieldIdentifier(parameter.name), it, !(parameter.required ?: false)) } private fun Path.toSegments(parameters: List) = value.split("/").drop(1).map { segment -> val isParam = segment.isNotEmpty() && segment[0] == '{' && segment[segment.length - 1] == '}' @@ -512,7 +513,7 @@ object OpenApiV2Parser { ?.let { it.type?.toPrimitive() } ?.let { Endpoint.Segment.Param( - Identifier(param), + FieldIdentifier(param), Reference.Primitive(it, false) ) } diff --git a/src/converter/openapi/src/commonMain/kotlin/community/flock/wirespec/openapi/v3/OpenApiV3Parser.kt b/src/converter/openapi/src/commonMain/kotlin/community/flock/wirespec/openapi/v3/OpenApiV3Parser.kt index e1258909..e94b6ad9 100644 --- a/src/converter/openapi/src/commonMain/kotlin/community/flock/wirespec/openapi/v3/OpenApiV3Parser.kt +++ b/src/converter/openapi/src/commonMain/kotlin/community/flock/wirespec/openapi/v3/OpenApiV3Parser.kt @@ -20,10 +20,11 @@ import community.flock.kotlinx.openapi.bindings.v3.SchemaOrReferenceObject import community.flock.kotlinx.openapi.bindings.v3.SchemaOrReferenceOrBooleanObject import community.flock.kotlinx.openapi.bindings.v3.StatusCode import community.flock.wirespec.compiler.core.parse.AST +import community.flock.wirespec.compiler.core.parse.DefinitionIdentifier import community.flock.wirespec.compiler.core.parse.Endpoint import community.flock.wirespec.compiler.core.parse.Enum import community.flock.wirespec.compiler.core.parse.Field -import community.flock.wirespec.compiler.core.parse.Identifier +import community.flock.wirespec.compiler.core.parse.FieldIdentifier import community.flock.wirespec.compiler.core.parse.Reference import community.flock.wirespec.compiler.core.parse.Type import community.flock.wirespec.compiler.core.parse.Union @@ -115,7 +116,7 @@ object OpenApiV3Parser { Endpoint( comment = null, - identifier = Identifier(name), + identifier = DefinitionIdentifier(name), method = method, path = segments, queries = query, @@ -221,7 +222,7 @@ object OpenApiV3Parser { ?.let { toReference(it, className(name, "Parameter", param)) } ?.let { Endpoint.Segment.Param( - Identifier(param), + FieldIdentifier(param), it ) } @@ -350,7 +351,7 @@ object OpenApiV3Parser { schemaObject.oneOf != null || schemaObject.anyOf != null -> listOf( Union( comment = null, - identifier = Identifier(name), + identifier = DefinitionIdentifier(name), entries = schemaObject.oneOf!! .mapIndexed { index, it -> when (it) { @@ -371,7 +372,7 @@ object OpenApiV3Parser { schemaObject.allOf != null -> listOf( Type( comment = null, - identifier = Identifier(name), + identifier = DefinitionIdentifier(name), shape = Type.Shape(schemaObject.allOf.orEmpty().flatMap { toField(resolve(it), name) } .distinctBy { it.identifier }), extends = emptyList(), @@ -392,7 +393,7 @@ object OpenApiV3Parser { schemaObject.enum != null -> schemaObject.enum!! .map { it.content } .toSet() - .let { listOf(Enum(comment = null, identifier = Identifier(name), entries = it)) } + .let { listOf(Enum(comment = null, identifier = DefinitionIdentifier(name), entries = it)) } else -> when (schemaObject.type) { null, OpenapiType.OBJECT -> { @@ -402,7 +403,7 @@ object OpenApiV3Parser { val schema = listOf( Type( comment = null, - identifier = Identifier(name), + identifier = DefinitionIdentifier(name), shape = Type.Shape(toField(schemaObject, name)), extends = emptyList(), ) @@ -535,7 +536,7 @@ object OpenApiV3Parser { when (value) { is SchemaObject -> { Field( - identifier = Identifier(key), + identifier = FieldIdentifier(key), reference = when { value.enum != null -> toReference(value, className(name, key)) value.type == OpenapiType.ARRAY -> toReference(value, className(name, key, "Array")) @@ -547,7 +548,7 @@ object OpenApiV3Parser { is ReferenceObject -> { Field( - Identifier(key), + FieldIdentifier(key), Reference.Custom(className(value.getReference()), false), !(schema.required?.contains(key) ?: false) ) @@ -560,14 +561,14 @@ object OpenApiV3Parser { is ReferenceObject -> toReference(s) is SchemaObject -> toReference(s, name) null -> Reference.Primitive(Reference.Primitive.Type.String) - }.let { Field(Identifier(parameter.name), it, !(parameter.required ?: false)) } + }.let { Field(FieldIdentifier(parameter.name), it, !(parameter.required ?: false)) } private fun OpenAPIObject.toField(header: HeaderObject, identifier: String, name: String) = when (val s = header.schema) { is ReferenceObject -> toReference(s) is SchemaObject -> toReference(s, name) null -> Reference.Primitive(Reference.Primitive.Type.String) - }.let { Field(Identifier(identifier), it, !(header.required ?: false)) } + }.let { Field(FieldIdentifier(identifier), it, !(header.required ?: false)) } private data class FlattenRequest( val path: Path, diff --git a/src/converter/openapi/src/commonTest/kotlin/community/flock/wirespec/openapi/common/Expected.kt b/src/converter/openapi/src/commonTest/kotlin/community/flock/wirespec/openapi/common/Expected.kt index 5f030a9a..0c1a4b84 100644 --- a/src/converter/openapi/src/commonTest/kotlin/community/flock/wirespec/openapi/common/Expected.kt +++ b/src/converter/openapi/src/commonTest/kotlin/community/flock/wirespec/openapi/common/Expected.kt @@ -1,9 +1,10 @@ package community.flock.wirespec.openapi.common +import community.flock.wirespec.compiler.core.parse.DefinitionIdentifier import community.flock.wirespec.compiler.core.parse.Endpoint import community.flock.wirespec.compiler.core.parse.Enum import community.flock.wirespec.compiler.core.parse.Field -import community.flock.wirespec.compiler.core.parse.Identifier +import community.flock.wirespec.compiler.core.parse.FieldIdentifier import community.flock.wirespec.compiler.core.parse.Reference import community.flock.wirespec.compiler.core.parse.Type import community.flock.wirespec.compiler.core.parse.Union @@ -13,7 +14,7 @@ object Expected { val objectInRequest = listOf( Endpoint( comment = null, - identifier = Identifier("TestWithDashGET"), + identifier = DefinitionIdentifier("TestWithDashGET"), method = Endpoint.Method.GET, path = listOf(Endpoint.Segment.Literal(value = "test-with-dash")), queries = emptyList(), @@ -42,16 +43,16 @@ object Expected { ), Type( comment = null, - identifier = Identifier("TestWithDashGETRequestBody"), + identifier = DefinitionIdentifier("TestWithDashGETRequestBody"), shape = Type.Shape( value = listOf( Field( - identifier = Identifier("id"), + identifier = FieldIdentifier("id"), reference = Reference.Primitive(type = Reference.Primitive.Type.String, isIterable = false), isNullable = true ), Field( - identifier = Identifier("nest"), + identifier = FieldIdentifier("nest"), reference = Reference.Custom(value = "TestWithDashGETRequestBodyNest", isIterable = false), isNullable = true ) @@ -61,16 +62,16 @@ object Expected { ), Type( comment = null, - identifier = Identifier("TestWithDashGETRequestBodyNest"), + identifier = DefinitionIdentifier("TestWithDashGETRequestBodyNest"), shape = Type.Shape( value = listOf( Field( - identifier = Identifier("a"), + identifier = FieldIdentifier("a"), reference = Reference.Primitive(type = Reference.Primitive.Type.Number, isIterable = false), isNullable = true ), Field( - identifier = Identifier("b"), + identifier = FieldIdentifier("b"), reference = Reference.Primitive(type = Reference.Primitive.Type.Number, isIterable = false), isNullable = true ) @@ -82,7 +83,7 @@ object Expected { val objectInResponse = listOf( Endpoint( comment = null, - identifier = Identifier("Test"), + identifier = DefinitionIdentifier("Test"), method = Endpoint.Method.GET, path = listOf(Endpoint.Segment.Literal(value = "test")), queries = emptyList(), @@ -110,11 +111,11 @@ object Expected { ), Type( comment = null, - identifier = Identifier("Test200ApplicationJsonResponseBody"), + identifier = DefinitionIdentifier("Test200ApplicationJsonResponseBody"), shape = Type.Shape( value = listOf( Field( - identifier = Identifier("id"), + identifier = FieldIdentifier("id"), reference = Reference.Primitive( type = Reference.Primitive.Type.String, isIterable = false @@ -122,7 +123,7 @@ object Expected { isNullable = true ), Field( - identifier = Identifier("nest"), + identifier = FieldIdentifier("nest"), reference = Reference.Custom( value = "Test200ApplicationJsonResponseBodyNest", isIterable = false @@ -135,11 +136,11 @@ object Expected { ), Type( comment = null, - identifier = Identifier("Test200ApplicationJsonResponseBodyNest"), + identifier = DefinitionIdentifier("Test200ApplicationJsonResponseBodyNest"), shape = Type.Shape( value = listOf( Field( - identifier = Identifier("a"), + identifier = FieldIdentifier("a"), reference = Reference.Primitive( type = Reference.Primitive.Type.Number, isIterable = false @@ -147,7 +148,7 @@ object Expected { isNullable = true ), Field( - identifier = Identifier("b"), + identifier = FieldIdentifier("b"), reference = Reference.Primitive( type = Reference.Primitive.Type.Number, isIterable = false @@ -162,7 +163,7 @@ object Expected { val additionalProperties = listOf( Endpoint( comment = null, - identifier = Identifier("AdditionalProperties"), + identifier = DefinitionIdentifier("AdditionalProperties"), method = Endpoint.Method.GET, path = listOf( Endpoint.Segment.Literal(value = "additional"), @@ -216,11 +217,11 @@ object Expected { ), Type( comment = null, - identifier = Identifier("AdditionalProperties404ApplicationJsonResponseBody"), + identifier = DefinitionIdentifier("AdditionalProperties404ApplicationJsonResponseBody"), shape = Type.Shape( value = listOf( Field( - identifier = Identifier("code"), + identifier = FieldIdentifier("code"), reference = Reference.Primitive( type = Reference.Primitive.Type.Integer, isIterable = false @@ -228,7 +229,7 @@ object Expected { isNullable = true ), Field( - identifier = Identifier("text"), + identifier = FieldIdentifier("text"), reference = Reference.Primitive( type = Reference.Primitive.Type.String, isIterable = false @@ -241,11 +242,11 @@ object Expected { ), Type( comment = null, - identifier = Identifier("Message"), + identifier = DefinitionIdentifier("Message"), shape = Type.Shape( value = listOf( Field( - identifier = Identifier("code"), + identifier = FieldIdentifier("code"), reference = Reference.Primitive( type = Reference.Primitive.Type.Integer, isIterable = false @@ -253,7 +254,7 @@ object Expected { isNullable = true ), Field( - identifier = Identifier("text"), + identifier = FieldIdentifier("text"), reference = Reference.Primitive( type = Reference.Primitive.Type.String, isIterable = false @@ -268,7 +269,7 @@ object Expected { val array = listOf( Endpoint( comment = null, - identifier = Identifier("ArrayGET"), + identifier = DefinitionIdentifier("ArrayGET"), method = Endpoint.Method.GET, path = listOf(Endpoint.Segment.Literal(value = "array")), queries = emptyList(), @@ -323,11 +324,11 @@ object Expected { ), Type( comment = null, - identifier = Identifier("ArrayGET200ApplicationJsonResponseBody"), + identifier = DefinitionIdentifier("ArrayGET200ApplicationJsonResponseBody"), shape = Type.Shape( value = listOf( Field( - identifier = Identifier("code"), + identifier = FieldIdentifier("code"), reference = Reference.Primitive( type = Reference.Primitive.Type.Number, isIterable = false @@ -335,7 +336,7 @@ object Expected { isNullable = true ), Field( - identifier = Identifier("text"), + identifier = FieldIdentifier("text"), reference = Reference.Primitive( type = Reference.Primitive.Type.String, isIterable = false @@ -348,11 +349,11 @@ object Expected { ), Type( comment = null, - identifier = Identifier("MessageArray"), + identifier = DefinitionIdentifier("MessageArray"), shape = Type.Shape( value = listOf( Field( - identifier = Identifier("code"), + identifier = FieldIdentifier("code"), reference = Reference.Primitive( type = Reference.Primitive.Type.Number, isIterable = false @@ -360,7 +361,7 @@ object Expected { isNullable = true ), Field( - identifier = Identifier("text"), + identifier = FieldIdentifier("text"), reference = Reference.Primitive( type = Reference.Primitive.Type.String, isIterable = false @@ -376,7 +377,7 @@ object Expected { val allOf = listOf( Endpoint( comment = null, - identifier = Identifier("AllofGET"), + identifier = DefinitionIdentifier("AllofGET"), method = Endpoint.Method.GET, path = listOf(Endpoint.Segment.Literal(value = "allof")), queries = emptyList(), @@ -405,11 +406,11 @@ object Expected { ), Type( comment = null, - identifier = Identifier("AllofGET200ApplicationJsonResponseBody"), + identifier = DefinitionIdentifier("AllofGET200ApplicationJsonResponseBody"), shape = Type.Shape( value = listOf( Field( - identifier = Identifier("a"), + identifier = FieldIdentifier("a"), reference = Reference.Primitive( type = Reference.Primitive.Type.String, isIterable = false @@ -417,7 +418,7 @@ object Expected { isNullable = true ), Field( - identifier = Identifier("b"), + identifier = FieldIdentifier("b"), reference = Reference.Primitive( type = Reference.Primitive.Type.String, isIterable = false @@ -425,7 +426,7 @@ object Expected { isNullable = false ), Field( - identifier = Identifier("c"), + identifier = FieldIdentifier("c"), reference = Reference.Primitive( type = Reference.Primitive.Type.String, isIterable = false @@ -433,7 +434,7 @@ object Expected { isNullable = true ), Field( - identifier = Identifier("d"), + identifier = FieldIdentifier("d"), reference = Reference.Custom( value = "AllofGET200ApplicationJsonResponseBodyD", isIterable = false @@ -446,11 +447,11 @@ object Expected { ), Type( comment = null, - identifier = Identifier("AllofGET200ApplicationJsonResponseBodyD"), + identifier = DefinitionIdentifier("AllofGET200ApplicationJsonResponseBodyD"), shape = Type.Shape( value = listOf( Field( - identifier = Identifier("e"), + identifier = FieldIdentifier("e"), reference = Reference.Primitive( type = Reference.Primitive.Type.String, isIterable = false, @@ -464,11 +465,11 @@ object Expected { ), Type( comment = null, - identifier = Identifier("Foo"), + identifier = DefinitionIdentifier("Foo"), shape = Type.Shape( value = listOf( Field( - identifier = Identifier("a"), + identifier = FieldIdentifier("a"), reference = Reference.Primitive( type = Reference.Primitive.Type.String, isIterable = false @@ -481,11 +482,11 @@ object Expected { ), Type( comment = null, - identifier = Identifier("Bar"), + identifier = DefinitionIdentifier("Bar"), shape = Type.Shape( value = listOf( Field( - identifier = Identifier("b"), + identifier = FieldIdentifier("b"), reference = Reference.Primitive( type = Reference.Primitive.Type.String, isIterable = false @@ -501,7 +502,7 @@ object Expected { val oneOf = listOf( Endpoint( comment = null, - identifier = Identifier("OneofGET"), + identifier = DefinitionIdentifier("OneofGET"), method = Endpoint.Method.GET, path = listOf(Endpoint.Segment.Literal(value = "oneof")), queries = emptyList(), @@ -530,7 +531,7 @@ object Expected { ), Union( comment = null, - identifier = Identifier("OneofGET200ApplicationJsonResponseBody"), + identifier = DefinitionIdentifier("OneofGET200ApplicationJsonResponseBody"), entries = setOf( Reference.Custom(value = "Foo", isIterable = false, isDictionary = false), Reference.Custom(value = "Bar", isIterable = false, isDictionary = false), @@ -548,11 +549,11 @@ object Expected { ), Type( comment = null, - identifier = Identifier("OneofGET200ApplicationJsonResponseBody2"), + identifier = DefinitionIdentifier("OneofGET200ApplicationJsonResponseBody2"), shape = Type.Shape( value = listOf( Field( - identifier = Identifier("c"), + identifier = FieldIdentifier("c"), reference = Reference.Primitive( type = Reference.Primitive.Type.String, isIterable = false, @@ -566,11 +567,11 @@ object Expected { ), Type( comment = null, - identifier = Identifier("OneofGET200ApplicationJsonResponseBody3"), + identifier = DefinitionIdentifier("OneofGET200ApplicationJsonResponseBody3"), shape = Type.Shape( value = listOf( Field( - identifier = Identifier("d"), + identifier = FieldIdentifier("d"), reference = Reference.Custom( value = "OneofGET200ApplicationJsonResponseBody3D", isIterable = false, @@ -584,11 +585,11 @@ object Expected { ), Type( comment = null, - identifier = Identifier("OneofGET200ApplicationJsonResponseBody3D"), + identifier = DefinitionIdentifier("OneofGET200ApplicationJsonResponseBody3D"), shape = Type.Shape( value = listOf( Field( - identifier = Identifier( + identifier = FieldIdentifier( "e" ), reference = Reference.Primitive( type = Reference.Primitive.Type.String, @@ -603,11 +604,11 @@ object Expected { ), Type( comment = null, - identifier = Identifier("Foo"), + identifier = DefinitionIdentifier("Foo"), shape = Type.Shape( value = listOf( Field( - identifier = Identifier("a"), + identifier = FieldIdentifier("a"), reference = Reference.Primitive( type = Reference.Primitive.Type.String, isIterable = false @@ -620,11 +621,11 @@ object Expected { ), Type( comment = null, - identifier = Identifier("Bar"), + identifier = DefinitionIdentifier("Bar"), shape = Type.Shape( value = listOf( Field( - identifier = Identifier("b"), + identifier = FieldIdentifier("b"), reference = Reference.Primitive( type = Reference.Primitive.Type.String, isIterable = false @@ -640,12 +641,12 @@ object Expected { val enum = listOf( Endpoint( comment = null, - identifier = Identifier("EnumGET"), + identifier = DefinitionIdentifier("EnumGET"), method = Endpoint.Method.GET, path = listOf(Endpoint.Segment.Literal(value = "enum")), queries = listOf( Field( - identifier = Identifier("order"), + identifier = FieldIdentifier("order"), reference = Reference.Custom( value = "EnumGETParameterOrder", isIterable = false, @@ -688,16 +689,16 @@ object Expected { ), Enum( comment = null, - identifier = Identifier("EnumGETParameterOrder"), + identifier = DefinitionIdentifier("EnumGETParameterOrder"), entries = setOf("ASC", "DESC") ), Type( comment = null, - identifier = Identifier("EnumGET201ApplicationJsonResponseBody"), + identifier = DefinitionIdentifier("EnumGET201ApplicationJsonResponseBody"), shape = Type.Shape( value = listOf( Field( - identifier = Identifier("code"), + identifier = FieldIdentifier("code"), reference = Reference.Custom( value = "EnumGET201ApplicationJsonResponseBodyCode", isIterable = false @@ -705,7 +706,7 @@ object Expected { isNullable = false ), Field( - identifier = Identifier("text"), + identifier = FieldIdentifier("text"), reference = Reference.Primitive( type = Reference.Primitive.Type.String, isIterable = false @@ -718,16 +719,16 @@ object Expected { ), Enum( comment = null, - identifier = Identifier("EnumGET201ApplicationJsonResponseBodyCode"), + identifier = DefinitionIdentifier("EnumGET201ApplicationJsonResponseBodyCode"), entries = setOf("WARNING", "ERROR") ), Type( comment = null, - identifier = Identifier("Message"), + identifier = DefinitionIdentifier("Message"), shape = Type.Shape( value = listOf( Field( - identifier = Identifier("code"), + identifier = FieldIdentifier("code"), reference = Reference.Custom( value = "ErrorType", isIterable = true @@ -735,7 +736,7 @@ object Expected { isNullable = false ), Field( - identifier = Identifier("text"), + identifier = FieldIdentifier("text"), reference = Reference.Primitive( type = Reference.Primitive.Type.String, isIterable = false @@ -748,7 +749,7 @@ object Expected { ), Enum( comment = null, - identifier = Identifier("ErrorType"), + identifier = DefinitionIdentifier("ErrorType"), entries = setOf("WARNING", "ERROR") ) ) diff --git a/src/converter/openapi/src/commonTest/kotlin/community/flock/wirespec/openapi/v2/OpenApiV2ParserTest.kt b/src/converter/openapi/src/commonTest/kotlin/community/flock/wirespec/openapi/v2/OpenApiV2ParserTest.kt index 816ce730..9ce44883 100644 --- a/src/converter/openapi/src/commonTest/kotlin/community/flock/wirespec/openapi/v2/OpenApiV2ParserTest.kt +++ b/src/converter/openapi/src/commonTest/kotlin/community/flock/wirespec/openapi/v2/OpenApiV2ParserTest.kt @@ -2,10 +2,11 @@ package community.flock.wirespec.openapi.v2 import com.goncalossilva.resources.Resource import community.flock.kotlinx.openapi.bindings.v2.OpenAPI +import community.flock.wirespec.compiler.core.parse.DefinitionIdentifier import community.flock.wirespec.compiler.core.parse.Endpoint import community.flock.wirespec.compiler.core.parse.Enum import community.flock.wirespec.compiler.core.parse.Field -import community.flock.wirespec.compiler.core.parse.Identifier +import community.flock.wirespec.compiler.core.parse.FieldIdentifier import community.flock.wirespec.compiler.core.parse.Reference.Custom import community.flock.wirespec.compiler.core.parse.Reference.Primitive import community.flock.wirespec.compiler.core.parse.Type @@ -27,21 +28,21 @@ class OpenApiV2ParserTest { val expectedTypeDefinitions = listOf( Type( comment = null, - identifier = Identifier("ApiResponse"), + identifier = DefinitionIdentifier("ApiResponse"), shape = Shape( value = listOf( Field( - identifier = Identifier("code"), + identifier = FieldIdentifier("code"), reference = Primitive(type = Primitive.Type.Integer, isIterable = false), isNullable = true ), Field( - identifier = Identifier("type"), + identifier = FieldIdentifier("type"), reference = Primitive(type = Primitive.Type.String, isIterable = false), isNullable = true ), Field( - identifier = Identifier("message"), + identifier = FieldIdentifier("message"), reference = Primitive(type = Primitive.Type.String, isIterable = false), isNullable = true ) @@ -51,16 +52,16 @@ class OpenApiV2ParserTest { ), Type( comment = null, - identifier = Identifier("Category"), + identifier = DefinitionIdentifier("Category"), shape = Shape( value = listOf( Field( - identifier = Identifier("id"), + identifier = FieldIdentifier("id"), reference = Primitive(type = Primitive.Type.Integer, isIterable = false), isNullable = true ), Field( - identifier = Identifier("name"), + identifier = FieldIdentifier("name"), reference = Primitive(type = Primitive.Type.String, isIterable = false), isNullable = true ) @@ -70,36 +71,36 @@ class OpenApiV2ParserTest { ), Type( comment = null, - identifier = Identifier("Pet"), + identifier = DefinitionIdentifier("Pet"), shape = Shape( value = listOf( Field( - identifier = Identifier("id"), + identifier = FieldIdentifier("id"), reference = Primitive(type = Primitive.Type.Integer, isIterable = false), isNullable = true ), Field( - identifier = Identifier("category"), + identifier = FieldIdentifier("category"), reference = Custom(value = "Category", isIterable = false), isNullable = true ), Field( - identifier = Identifier("name"), + identifier = FieldIdentifier("name"), reference = Primitive(type = Primitive.Type.String, isIterable = false), isNullable = false ), Field( - identifier = Identifier("photoUrls"), + identifier = FieldIdentifier("photoUrls"), reference = Primitive(type = Primitive.Type.String, isIterable = true), isNullable = false ), Field( - identifier = Identifier("tags"), + identifier = FieldIdentifier("tags"), reference = Custom(value = "Tag", isIterable = true), isNullable = true ), Field( - identifier = Identifier("status"), + identifier = FieldIdentifier("status"), reference = Custom(value = "PetStatus", isIterable = false), isNullable = true ) @@ -109,16 +110,16 @@ class OpenApiV2ParserTest { ), Type( comment = null, - identifier = Identifier("Tag"), + identifier = DefinitionIdentifier("Tag"), shape = Shape( value = listOf( Field( - identifier = Identifier("id"), + identifier = FieldIdentifier("id"), reference = Primitive(type = Primitive.Type.Integer, isIterable = false), isNullable = true ), Field( - identifier = Identifier("name"), + identifier = FieldIdentifier("name"), reference = Primitive(type = Primitive.Type.String, isIterable = false), isNullable = true ) @@ -128,36 +129,36 @@ class OpenApiV2ParserTest { ), Type( comment = null, - identifier = Identifier("Order"), + identifier = DefinitionIdentifier("Order"), shape = Shape( value = listOf( Field( - identifier = Identifier("id"), + identifier = FieldIdentifier("id"), reference = Primitive(type = Primitive.Type.Integer, isIterable = false), isNullable = true ), Field( - identifier = Identifier("petId"), + identifier = FieldIdentifier("petId"), reference = Primitive(type = Primitive.Type.Integer, isIterable = false), isNullable = true ), Field( - identifier = Identifier("quantity"), + identifier = FieldIdentifier("quantity"), reference = Primitive(type = Primitive.Type.Integer, isIterable = false), isNullable = true ), Field( - identifier = Identifier("shipDate"), + identifier = FieldIdentifier("shipDate"), reference = Primitive(type = Primitive.Type.String, isIterable = false), isNullable = true ), Field( - identifier = Identifier("status"), + identifier = FieldIdentifier("status"), reference = Custom(value = "OrderStatus", isIterable = false), isNullable = true ), Field( - identifier = Identifier("complete"), + identifier = FieldIdentifier("complete"), reference = Primitive(type = Primitive.Type.Boolean, isIterable = false), isNullable = true ) @@ -167,46 +168,46 @@ class OpenApiV2ParserTest { ), Type( comment = null, - identifier = Identifier("User"), + identifier = DefinitionIdentifier("User"), shape = Shape( value = listOf( Field( - identifier = Identifier("id"), + identifier = FieldIdentifier("id"), reference = Primitive(type = Primitive.Type.Integer, isIterable = false), isNullable = true ), Field( - identifier = Identifier("username"), + identifier = FieldIdentifier("username"), reference = Primitive(type = Primitive.Type.String, isIterable = false), isNullable = true ), Field( - identifier = Identifier("firstName"), + identifier = FieldIdentifier("firstName"), reference = Primitive(type = Primitive.Type.String, isIterable = false), isNullable = true ), Field( - identifier = Identifier("lastName"), + identifier = FieldIdentifier("lastName"), reference = Primitive(type = Primitive.Type.String, isIterable = false), isNullable = true ), Field( - identifier = Identifier("email"), + identifier = FieldIdentifier("email"), reference = Primitive(type = Primitive.Type.String, isIterable = false), isNullable = true ), Field( - identifier = Identifier("password"), + identifier = FieldIdentifier("password"), reference = Primitive(type = Primitive.Type.String, isIterable = false), isNullable = true ), Field( - identifier = Identifier("phone"), + identifier = FieldIdentifier("phone"), reference = Primitive(type = Primitive.Type.String, isIterable = false), isNullable = true ), Field( - identifier = Identifier("userStatus"), + identifier = FieldIdentifier("userStatus"), reference = Primitive(type = Primitive.Type.Integer, isIterable = false), isNullable = true ) @@ -219,12 +220,12 @@ class OpenApiV2ParserTest { val expectedEnumDefinitions = listOf( Enum( comment = null, - identifier = Identifier("PetStatus"), + identifier = DefinitionIdentifier("PetStatus"), entries = setOf("available", "pending", "sold") ), Enum( comment = null, - identifier = Identifier("OrderStatus"), + identifier = DefinitionIdentifier("OrderStatus"), entries = setOf("placed", "approved", "delivered") ) ) @@ -270,7 +271,7 @@ class OpenApiV2ParserTest { val expected = listOf( Endpoint( comment = null, - identifier = Identifier("AlisaGET"), + identifier = DefinitionIdentifier("AlisaGET"), method = Endpoint.Method.GET, path = listOf(Endpoint.Segment.Literal(value = "alisa")), queries = emptyList(), @@ -291,11 +292,11 @@ class OpenApiV2ParserTest { ), Type( comment = null, - identifier = Identifier("Foo"), + identifier = DefinitionIdentifier("Foo"), shape = Shape( value = listOf( Field( - identifier = Identifier("a"), + identifier = FieldIdentifier("a"), reference = Primitive( type = Primitive.Type.String, isIterable = false, diff --git a/src/converter/openapi/src/commonTest/kotlin/community/flock/wirespec/openapi/v3/OpenApiV3ParserTest.kt b/src/converter/openapi/src/commonTest/kotlin/community/flock/wirespec/openapi/v3/OpenApiV3ParserTest.kt index aa1d1739..d32d0696 100644 --- a/src/converter/openapi/src/commonTest/kotlin/community/flock/wirespec/openapi/v3/OpenApiV3ParserTest.kt +++ b/src/converter/openapi/src/commonTest/kotlin/community/flock/wirespec/openapi/v3/OpenApiV3ParserTest.kt @@ -2,10 +2,11 @@ package community.flock.wirespec.openapi.v3 import com.goncalossilva.resources.Resource import community.flock.kotlinx.openapi.bindings.v3.OpenAPI +import community.flock.wirespec.compiler.core.parse.DefinitionIdentifier import community.flock.wirespec.compiler.core.parse.Endpoint import community.flock.wirespec.compiler.core.parse.Enum import community.flock.wirespec.compiler.core.parse.Field -import community.flock.wirespec.compiler.core.parse.Identifier +import community.flock.wirespec.compiler.core.parse.FieldIdentifier import community.flock.wirespec.compiler.core.parse.Reference import community.flock.wirespec.compiler.core.parse.Reference.Primitive import community.flock.wirespec.compiler.core.parse.Type @@ -27,16 +28,16 @@ class OpenApiV3ParserTest { val expect = listOf( Enum( comment = null, - identifier = Identifier("FindPetsByStatusParameterStatus"), + identifier = DefinitionIdentifier("FindPetsByStatusParameterStatus"), entries = setOf("available", "pending", "sold") ), Type( comment = null, - identifier = Identifier("Order"), + identifier = DefinitionIdentifier("Order"), shape = Shape( value = listOf( Field( - identifier = Identifier("id"), + identifier = FieldIdentifier("id"), reference = Primitive( type = Primitive.Type.Integer, isIterable = false, @@ -45,7 +46,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("petId"), + identifier = FieldIdentifier("petId"), reference = Primitive( type = Primitive.Type.Integer, isIterable = false, @@ -54,7 +55,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("quantity"), + identifier = FieldIdentifier("quantity"), reference = Primitive( type = Primitive.Type.Integer, isIterable = false, @@ -63,7 +64,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("shipDate"), + identifier = FieldIdentifier("shipDate"), reference = Primitive( type = Primitive.Type.String, isIterable = false, @@ -72,7 +73,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("status"), + identifier = FieldIdentifier("status"), reference = Reference.Custom( value = "OrderStatus", isIterable = false, @@ -81,7 +82,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("complete"), + identifier = FieldIdentifier("complete"), reference = Primitive( type = Primitive.Type.Boolean, isIterable = false, @@ -95,16 +96,16 @@ class OpenApiV3ParserTest { ), Enum( comment = null, - identifier = Identifier("OrderStatus"), + identifier = DefinitionIdentifier("OrderStatus"), entries = setOf("placed", "approved", "delivered"), ), Type( comment = null, - identifier = Identifier("Customer"), + identifier = DefinitionIdentifier("Customer"), shape = Shape( value = listOf( Field( - identifier = Identifier("id"), + identifier = FieldIdentifier("id"), reference = Primitive( type = Primitive.Type.Integer, isIterable = false, @@ -113,7 +114,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("username"), + identifier = FieldIdentifier("username"), reference = Primitive( type = Primitive.Type.String, isIterable = false, @@ -122,7 +123,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("address"), + identifier = FieldIdentifier("address"), reference = Reference.Custom(value = "Address", isIterable = true, isDictionary = false), isNullable = true ) @@ -132,11 +133,11 @@ class OpenApiV3ParserTest { ), Type( comment = null, - identifier = Identifier("Address"), + identifier = DefinitionIdentifier("Address"), shape = Shape( value = listOf( Field( - identifier = Identifier("street"), + identifier = FieldIdentifier("street"), reference = Primitive( type = Primitive.Type.String, isIterable = false, @@ -145,7 +146,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("city"), + identifier = FieldIdentifier("city"), reference = Primitive( type = Primitive.Type.String, isIterable = false, @@ -154,7 +155,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("state"), + identifier = FieldIdentifier("state"), reference = Primitive( type = Primitive.Type.String, isIterable = false, @@ -163,7 +164,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("zip"), + identifier = FieldIdentifier("zip"), reference = Primitive( type = Primitive.Type.String, isIterable = false, @@ -177,11 +178,11 @@ class OpenApiV3ParserTest { ), Type( comment = null, - identifier = Identifier("Category"), + identifier = DefinitionIdentifier("Category"), shape = Shape( value = listOf( Field( - identifier = Identifier("id"), + identifier = FieldIdentifier("id"), reference = Primitive( type = Primitive.Type.Integer, isIterable = false, @@ -190,7 +191,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("name"), + identifier = FieldIdentifier("name"), reference = Primitive( type = Primitive.Type.String, isIterable = false, @@ -204,11 +205,11 @@ class OpenApiV3ParserTest { ), Type( comment = null, - identifier = Identifier("User"), + identifier = DefinitionIdentifier("User"), shape = Shape( value = listOf( Field( - identifier = Identifier("id"), + identifier = FieldIdentifier("id"), reference = Primitive( type = Primitive.Type.Integer, isIterable = false, @@ -217,7 +218,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("username"), + identifier = FieldIdentifier("username"), reference = Primitive( type = Primitive.Type.String, isIterable = false, @@ -226,7 +227,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("firstName"), + identifier = FieldIdentifier("firstName"), reference = Primitive( type = Primitive.Type.String, isIterable = false, @@ -235,7 +236,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("lastName"), + identifier = FieldIdentifier("lastName"), reference = Primitive( type = Primitive.Type.String, isIterable = false, @@ -244,7 +245,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("email"), + identifier = FieldIdentifier("email"), reference = Primitive( type = Primitive.Type.String, isIterable = false, @@ -253,7 +254,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("password"), + identifier = FieldIdentifier("password"), reference = Primitive( type = Primitive.Type.String, isIterable = false, @@ -262,7 +263,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("phone"), + identifier = FieldIdentifier("phone"), reference = Primitive( type = Primitive.Type.String, isIterable = false, @@ -271,7 +272,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("userStatus"), + identifier = FieldIdentifier("userStatus"), reference = Primitive( type = Primitive.Type.Integer, isIterable = false, @@ -285,11 +286,11 @@ class OpenApiV3ParserTest { ), Type( comment = null, - identifier = Identifier("Tag"), + identifier = DefinitionIdentifier("Tag"), shape = Shape( value = listOf( Field( - identifier = Identifier("id"), + identifier = FieldIdentifier("id"), reference = Primitive( type = Primitive.Type.Integer, isIterable = false, @@ -298,7 +299,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("name"), + identifier = FieldIdentifier("name"), reference = Primitive( type = Primitive.Type.String, isIterable = false, @@ -312,11 +313,11 @@ class OpenApiV3ParserTest { ), Type( comment = null, - identifier = Identifier("Pet"), + identifier = DefinitionIdentifier("Pet"), shape = Shape( value = listOf( Field( - identifier = Identifier("id"), + identifier = FieldIdentifier("id"), reference = Primitive( type = Primitive.Type.Integer, isIterable = false, @@ -325,7 +326,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("name"), + identifier = FieldIdentifier("name"), reference = Primitive( type = Primitive.Type.String, isIterable = false, @@ -334,7 +335,7 @@ class OpenApiV3ParserTest { isNullable = false ), Field( - identifier = Identifier("category"), + identifier = FieldIdentifier("category"), reference = Reference.Custom( value = "Category", isIterable = false, @@ -343,7 +344,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("photoUrls"), + identifier = FieldIdentifier("photoUrls"), reference = Primitive( type = Primitive.Type.String, isIterable = true, @@ -352,7 +353,7 @@ class OpenApiV3ParserTest { isNullable = false ), Field( - identifier = Identifier("tags"), + identifier = FieldIdentifier("tags"), reference = Reference.Custom( value = "Tag", isIterable = true, @@ -361,7 +362,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("status"), + identifier = FieldIdentifier("status"), reference = Reference.Custom( value = "PetStatus", isIterable = false, @@ -375,16 +376,16 @@ class OpenApiV3ParserTest { ), Enum( comment = null, - identifier = Identifier("PetStatus"), + identifier = DefinitionIdentifier("PetStatus"), entries = setOf("available", "pending", "sold"), ), Type( comment = null, - identifier = Identifier("ApiResponse"), + identifier = DefinitionIdentifier("ApiResponse"), shape = Shape( value = listOf( Field( - identifier = Identifier("code"), + identifier = FieldIdentifier("code"), reference = Primitive( type = Primitive.Type.Integer, isIterable = false, @@ -393,7 +394,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("type"), + identifier = FieldIdentifier("type"), reference = Primitive( type = Primitive.Type.String, isIterable = false, @@ -402,7 +403,7 @@ class OpenApiV3ParserTest { isNullable = true ), Field( - identifier = Identifier("message"), + identifier = FieldIdentifier("message"), reference = Primitive( type = Primitive.Type.String, isIterable = false, @@ -423,7 +424,7 @@ class OpenApiV3ParserTest { val expectedEndpoint = Endpoint( comment = null, - identifier = Identifier("GetInventory"), + identifier = DefinitionIdentifier("GetInventory"), method = Endpoint.Method.GET, path = listOf(Endpoint.Segment.Literal(value = "store"), Endpoint.Segment.Literal(value = "inventory")), queries = emptyList(), @@ -455,12 +456,12 @@ class OpenApiV3ParserTest { val expect = listOf( Endpoint( comment = null, - identifier = Identifier("PizzasPizzaIdIngredientsGET"), + identifier = DefinitionIdentifier("PizzasPizzaIdIngredientsGET"), method = Endpoint.Method.GET, path = listOf( Endpoint.Segment.Literal("pizzas"), Endpoint.Segment.Param( - Identifier("pizzaId"), + FieldIdentifier("pizzaId"), Primitive(type = Primitive.Type.String, isIterable = false) ), Endpoint.Segment.Literal("ingredients"), @@ -486,12 +487,12 @@ class OpenApiV3ParserTest { ), Type( comment = null, - identifier = Identifier("Ingredient"), + identifier = DefinitionIdentifier("Ingredient"), shape = Shape( listOf( - Field(Identifier("id"), Primitive(Primitive.Type.String, false), true), - Field(Identifier("name"), Primitive(Primitive.Type.String, false), true), - Field(Identifier("quantity"), Primitive(Primitive.Type.String, false), true), + Field(FieldIdentifier("id"), Primitive(Primitive.Type.String, false), true), + Field(FieldIdentifier("name"), Primitive(Primitive.Type.String, false), true), + Field(FieldIdentifier("quantity"), Primitive(Primitive.Type.String, false), true), ) ), extends = emptyList(), @@ -512,16 +513,16 @@ class OpenApiV3ParserTest { val expect = listOf( Endpoint( comment = null, - identifier = Identifier("TodosList"), + identifier = DefinitionIdentifier("TodosList"), method = Endpoint.Method.GET, path = listOf( Endpoint.Segment.Literal("todos") ), queries = listOf( - Field(Identifier("completed"), Primitive(type = Primitive.Type.Boolean, isIterable = false), true) + Field(FieldIdentifier("completed"), Primitive(type = Primitive.Type.Boolean, isIterable = false), true) ), headers = listOf( - Field(Identifier("x-user"), Primitive(type = Primitive.Type.Boolean, isIterable = false), true) + Field(FieldIdentifier("x-user"), Primitive(type = Primitive.Type.Boolean, isIterable = false), true) ), cookies = listOf(), requests = listOf( @@ -542,14 +543,14 @@ class OpenApiV3ParserTest { ), Endpoint( comment = null, - identifier = Identifier("TodosPOST"), + identifier = DefinitionIdentifier("TodosPOST"), method = Endpoint.Method.POST, path = listOf( Endpoint.Segment.Literal("todos"), ), queries = listOf(), headers = listOf( - Field(Identifier("x-user"), Primitive(type = Primitive.Type.Boolean, isIterable = false), true) + Field(FieldIdentifier("x-user"), Primitive(type = Primitive.Type.Boolean, isIterable = false), true) ), cookies = listOf(), requests = listOf( @@ -587,11 +588,11 @@ class OpenApiV3ParserTest { ), Endpoint( comment = null, - identifier = Identifier("TodosIdGET"), + identifier = DefinitionIdentifier("TodosIdGET"), method = Endpoint.Method.GET, path = listOf( Endpoint.Segment.Literal("todos"), - Endpoint.Segment.Param(Identifier("id"), Primitive(Primitive.Type.String, false)) + Endpoint.Segment.Param(FieldIdentifier("id"), Primitive(Primitive.Type.String, false)) ), queries = listOf(), headers = listOf(), @@ -622,69 +623,69 @@ class OpenApiV3ParserTest { ), Type( comment = null, - identifier = Identifier("Todo_input"), + identifier = DefinitionIdentifier("Todo_input"), shape = Shape( listOf( - Field(Identifier("title"), Primitive(Primitive.Type.String, false), true), - Field(Identifier("completed"), Primitive(Primitive.Type.Boolean, false), true) + Field(FieldIdentifier("title"), Primitive(Primitive.Type.String, false), true), + Field(FieldIdentifier("completed"), Primitive(Primitive.Type.Boolean, false), true) ) ), extends = emptyList(), ), Type( comment = null, - identifier = Identifier("Todo"), + identifier = DefinitionIdentifier("Todo"), shape = Shape( listOf( - Field(Identifier("id"), Primitive(Primitive.Type.String, false), true), - Field(Identifier("title"), Primitive(Primitive.Type.String, false), true), - Field(Identifier("completed"), Primitive(Primitive.Type.Boolean, false), true), - Field(Identifier("alert"), Reference.Custom("TodoAlert", false), true), + Field(FieldIdentifier("id"), Primitive(Primitive.Type.String, false), true), + Field(FieldIdentifier("title"), Primitive(Primitive.Type.String, false), true), + Field(FieldIdentifier("completed"), Primitive(Primitive.Type.Boolean, false), true), + Field(FieldIdentifier("alert"), Reference.Custom("TodoAlert", false), true), ) ), extends = emptyList(), ), Type( comment = null, - identifier = Identifier("TodoAlert"), + identifier = DefinitionIdentifier("TodoAlert"), shape = Shape( listOf( - Field(Identifier("code"), Primitive(Primitive.Type.String, false), true), - Field(Identifier("message"), Reference.Custom("TodoAlertMessage", false), true), + Field(FieldIdentifier("code"), Primitive(Primitive.Type.String, false), true), + Field(FieldIdentifier("message"), Reference.Custom("TodoAlertMessage", false), true), ) ), extends = emptyList(), ), Type( comment = null, - identifier = Identifier("TodoAlertMessage"), + identifier = DefinitionIdentifier("TodoAlertMessage"), shape = Shape( listOf( - Field(Identifier("key"), Primitive(Primitive.Type.String, false), true), - Field(Identifier("value"), Primitive(Primitive.Type.String, false), true), + Field(FieldIdentifier("key"), Primitive(Primitive.Type.String, false), true), + Field(FieldIdentifier("value"), Primitive(Primitive.Type.String, false), true), ) ), extends = emptyList(), ), Type( comment = null, - identifier = Identifier("TodosnestedArray"), + identifier = DefinitionIdentifier("TodosnestedArray"), shape = Shape( listOf( - Field(Identifier("id"), Primitive(Primitive.Type.String, false), true), - Field(Identifier("title"), Primitive(Primitive.Type.String, false), true), - Field(Identifier("nested"), Primitive(Primitive.Type.Boolean, false), true), + Field(FieldIdentifier("id"), Primitive(Primitive.Type.String, false), true), + Field(FieldIdentifier("title"), Primitive(Primitive.Type.String, false), true), + Field(FieldIdentifier("nested"), Primitive(Primitive.Type.Boolean, false), true), ) ), extends = emptyList(), ), Type( comment = null, - identifier = Identifier("Error"), + identifier = DefinitionIdentifier("Error"), shape = Shape( listOf( - Field(Identifier("code"), Primitive(Primitive.Type.String, false), true), - Field(Identifier("message"), Primitive(Primitive.Type.String, false), true), + Field(FieldIdentifier("code"), Primitive(Primitive.Type.String, false), true), + Field(FieldIdentifier("message"), Primitive(Primitive.Type.String, false), true), ) ), extends = emptyList(),