Skip to content

Commit c0c3c48

Browse files
trobertadamw
andauthored
Update schemaId URL for MetaSchemaDraft202012 to use https (#4954)
Since draft 2019-09, all meta-schema URIs should use `https://`. Also dropping the trailing `#` which is no longer used in official examples. Some third-party tools fail to recognize meta-schema URIs using the http scheme. ref: - https://json-schema.org/draft/2020-12/schema ("$id") - https://json-schema.org/understanding-json-schema/reference/schema - https://json-schema.org/specification-links#draft-2019-09-(formerly-known-as-draft-8) --------- Co-authored-by: Adam Warski <[email protected]>
1 parent 74c338f commit c0c3c48

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

docs/apispec-docs/src/main/scala/sttp/tapir/docs/apispec/schema/MetaSchema.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ case object MetaSchemaDraft04 extends MetaSchema {
99
}
1010

1111
case object MetaSchemaDraft202012 extends MetaSchema {
12-
override lazy val schemaId: String = "http://json-schema.org/draft/2020-12/schema#"
12+
override lazy val schemaId: String = "https://json-schema.org/draft/2020-12/schema"
1313
}

docs/apispec-docs/src/test/scala/sttp/tapir/docs/apispec/schema/TapirSchemaToJsonSchemaTest.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class TapirSchemaToJsonSchemaTest extends AnyFlatSpec with Matchers with OptionV
2626
val result: ASchema = TapirSchemaToJsonSchema(tSchema, markOptionsAsNullable = true)
2727

2828
// then
29-
result.asJson.deepDropNullValues shouldBe json"""{"$$schema":"http://json-schema.org/draft/2020-12/schema#","title":"Parent","required":["innerChildField"],"type":"object","properties":{"innerChildField":{"$$ref":"#/$$defs/Child"}},"$$defs":{"Child":{"title":"Child","required":["childId"],"type":"object","properties":{"childId":{"type":"string"},"childNames":{"type":"array","items":{"type":"string"}}}}}}"""
29+
result.asJson.deepDropNullValues shouldBe json"""{"$$schema":"https://json-schema.org/draft/2020-12/schema","title":"Parent","required":["innerChildField"],"type":"object","properties":{"innerChildField":{"$$ref":"#/$$defs/Child"}},"$$defs":{"Child":{"title":"Child","required":["childId"],"type":"object","properties":{"childId":{"type":"string"},"childNames":{"type":"array","items":{"type":"string"}}}}}}"""
3030

3131
}
3232

@@ -38,7 +38,7 @@ class TapirSchemaToJsonSchemaTest extends AnyFlatSpec with Matchers with OptionV
3838
val result = TapirSchemaToJsonSchema(tSchema, markOptionsAsNullable = true)
3939

4040
// then
41-
result.asJson.deepDropNullValues shouldBe json"""{"$$schema":"http://json-schema.org/draft/2020-12/schema#","type":"array","items":{"type":"integer","format":"int32"}}"""
41+
result.asJson.deepDropNullValues shouldBe json"""{"$$schema":"https://json-schema.org/draft/2020-12/schema","type":"array","items":{"type":"integer","format":"int32"}}"""
4242
}
4343

4444
it should "handle repeated type names" in {
@@ -54,7 +54,7 @@ class TapirSchemaToJsonSchemaTest extends AnyFlatSpec with Matchers with OptionV
5454
val result = TapirSchemaToJsonSchema(tSchema, markOptionsAsNullable = true)
5555

5656
// then
57-
result.asJson.deepDropNullValues shouldBe json"""{"$$schema":"http://json-schema.org/draft/2020-12/schema#","title":"Parent","required":["innerChildField","childDetails"],"type":"object","properties":{"innerChildField":{"$$ref":"#/$$defs/Child"},"childDetails":{"$$ref":"#/$$defs/Child1"}},"$$defs":{"Child":{"title":"Child","required":["childName"],"type":"object","properties":{"childName":{"type":"string"}}},"Child1":{"title":"Child","required":["age"],"type":"object","properties":{"age":{"type":"integer","format":"int32"},"height":{"type":["integer", "null"],"format":"int32"}}}}}"""
57+
result.asJson.deepDropNullValues shouldBe json"""{"$$schema":"https://json-schema.org/draft/2020-12/schema","title":"Parent","required":["innerChildField","childDetails"],"type":"object","properties":{"innerChildField":{"$$ref":"#/$$defs/Child"},"childDetails":{"$$ref":"#/$$defs/Child1"}},"$$defs":{"Child":{"title":"Child","required":["childName"],"type":"object","properties":{"childName":{"type":"string"}}},"Child1":{"title":"Child","required":["age"],"type":"object","properties":{"age":{"type":"integer","format":"int32"},"height":{"type":["integer", "null"],"format":"int32"}}}}}"""
5858
}
5959

6060
it should "handle options as not nullable" in {
@@ -67,7 +67,7 @@ class TapirSchemaToJsonSchemaTest extends AnyFlatSpec with Matchers with OptionV
6767
val result = TapirSchemaToJsonSchema(tSchema, markOptionsAsNullable = false)
6868

6969
// then
70-
result.asJson.deepDropNullValues shouldBe json"""{"$$schema":"http://json-schema.org/draft/2020-12/schema#","title":"Parent","required":["innerChildField"],"type":"object","properties":{"innerChildField":{"$$ref":"#/$$defs/Child"}},"$$defs":{"Child":{"title":"Child","type":"object","properties":{"childName":{"type":"string"}}}}}"""
70+
result.asJson.deepDropNullValues shouldBe json"""{"$$schema":"https://json-schema.org/draft/2020-12/schema","title":"Parent","required":["innerChildField"],"type":"object","properties":{"innerChildField":{"$$ref":"#/$$defs/Child"}},"$$defs":{"Child":{"title":"Child","type":"object","properties":{"childName":{"type":"string"}}}}}"""
7171

7272
}
7373

@@ -81,7 +81,7 @@ class TapirSchemaToJsonSchemaTest extends AnyFlatSpec with Matchers with OptionV
8181
val result = TapirSchemaToJsonSchema(tSchema, markOptionsAsNullable = true)
8282

8383
// then
84-
result.asJson.deepDropNullValues shouldBe json"""{"$$schema":"http://json-schema.org/draft/2020-12/schema#","title":"Parent","required":["innerChildField"],"type":"object","properties":{"innerChildField":{"$$ref":"#/$$defs/Child"}},"$$defs":{"Child":{"title":"Child","type":"object","properties":{"childName":{"type":["string","null"]}}}}}"""
84+
result.asJson.deepDropNullValues shouldBe json"""{"$$schema":"https://json-schema.org/draft/2020-12/schema","title":"Parent","required":["innerChildField"],"type":"object","properties":{"innerChildField":{"$$ref":"#/$$defs/Child"}},"$$defs":{"Child":{"title":"Child","type":"object","properties":{"childName":{"type":["string","null"]}}}}}"""
8585
}
8686

8787
it should "use title from annotation or ref name" in {
@@ -100,7 +100,7 @@ class TapirSchemaToJsonSchemaTest extends AnyFlatSpec with Matchers with OptionV
100100
val result = TapirSchemaToJsonSchema(tSchema, markOptionsAsNullable = true)
101101

102102
// then
103-
result.asJson.deepDropNullValues shouldBe json"""{"$$schema":"http://json-schema.org/draft/2020-12/schema#","title":"MyOwnTitle1","required":["inner"],"type":"object","properties":{"inner":{"$$ref":"#/$$defs/Parent"}},"$$defs":{"Parent":{"title":"Parent","required":["innerChildField"],"type":"object","properties":{"innerChildField":{"$$ref":"#/$$defs/Child"}}},"Child":{"title":"MyOwnTitle3","type":"object","properties":{"childName":{"type":["string","null"]}}}}}"""
103+
result.asJson.deepDropNullValues shouldBe json"""{"$$schema":"https://json-schema.org/draft/2020-12/schema","title":"MyOwnTitle1","required":["inner"],"type":"object","properties":{"inner":{"$$ref":"#/$$defs/Parent"}},"$$defs":{"Parent":{"title":"Parent","required":["innerChildField"],"type":"object","properties":{"innerChildField":{"$$ref":"#/$$defs/Child"}}},"Child":{"title":"MyOwnTitle3","type":"object","properties":{"childName":{"type":["string","null"]}}}}}"""
104104
}
105105

106106
it should "NOT use generate default titles if disabled" in {
@@ -116,7 +116,7 @@ class TapirSchemaToJsonSchemaTest extends AnyFlatSpec with Matchers with OptionV
116116
val result = TapirSchemaToJsonSchema(tSchema, markOptionsAsNullable = true)
117117

118118
// then
119-
result.asJson.deepDropNullValues shouldBe json"""{"$$schema":"http://json-schema.org/draft/2020-12/schema#","title":"Parent","required":["innerChildField"],"type":"object","properties":{"innerChildField":{"$$ref":"#/$$defs/Child"}},"$$defs":{"Child":{"title":"MyChild","type":"object","properties":{"childName":{"type":["string","null"]}}}}}"""
119+
result.asJson.deepDropNullValues shouldBe json"""{"$$schema":"https://json-schema.org/draft/2020-12/schema","title":"Parent","required":["innerChildField"],"type":"object","properties":{"innerChildField":{"$$ref":"#/$$defs/Child"}},"$$defs":{"Child":{"title":"MyChild","type":"object","properties":{"childName":{"type":["string","null"]}}}}}"""
120120
}
121121

122122
it should "Generate correct names for Eithers with parameterized types" in {
@@ -158,7 +158,7 @@ class TapirSchemaToJsonSchemaTest extends AnyFlatSpec with Matchers with OptionV
158158

159159
// then
160160
result.asJson.deepDropNullValues shouldBe
161-
json"""{"$$schema" : "http://json-schema.org/draft/2020-12/schema#", "title" : "Tuple2_Int_String", "type" : "array", "prefixItems" : [{"type" : "integer", "format" : "int32"}, {"type" : "string"}]}"""
161+
json"""{"$$schema" : "https://json-schema.org/draft/2020-12/schema", "title" : "Tuple2_Int_String", "type" : "array", "prefixItems" : [{"type" : "integer", "format" : "int32"}, {"type" : "string"}]}"""
162162
}
163163

164164
it should "handle as nullable if marked with Nullable attribute" in {
@@ -175,7 +175,7 @@ class TapirSchemaToJsonSchemaTest extends AnyFlatSpec with Matchers with OptionV
175175
val result = TapirSchemaToJsonSchema(tSchema, markOptionsAsNullable = false)
176176

177177
// then
178-
result.asJson.deepDropNullValues shouldBe json"""{"$$schema":"http://json-schema.org/draft/2020-12/schema#","title":"Parent","required":["innerChildField","nullableInnerChild"],"type":"object","properties":{"innerChildField":{"$$ref":"#/$$defs/Child"},"nullableInnerChild":{"title":"Child","anyOf":[{"$$ref":"#/$$defs/Child"},{"type":"null"}]}},"$$defs":{"Child":{"title":"Child","type":"object","properties":{"childName":{"type":["string","null"]}}}}}"""
178+
result.asJson.deepDropNullValues shouldBe json"""{"$$schema":"https://json-schema.org/draft/2020-12/schema","title":"Parent","required":["innerChildField","nullableInnerChild"],"type":"object","properties":{"innerChildField":{"$$ref":"#/$$defs/Child"},"nullableInnerChild":{"title":"Child","anyOf":[{"$$ref":"#/$$defs/Child"},{"type":"null"}]}},"$$defs":{"Child":{"title":"Child","type":"object","properties":{"childName":{"type":["string","null"]}}}}}"""
179179
}
180180

181181
it should "generate a top-level array schema" in {
@@ -187,7 +187,7 @@ class TapirSchemaToJsonSchemaTest extends AnyFlatSpec with Matchers with OptionV
187187

188188
// then
189189
result.asJson shouldBe json"""{
190-
"$$schema" : "http://json-schema.org/draft/2020-12/schema#",
190+
"$$schema" : "https://json-schema.org/draft/2020-12/schema",
191191
"$$defs" : {
192192
"Test" : {
193193
"title" : "Test",
@@ -220,7 +220,7 @@ class TapirSchemaToJsonSchemaTest extends AnyFlatSpec with Matchers with OptionV
220220

221221
// then
222222
result.asJson shouldBe json"""{
223-
"$$schema" : "http://json-schema.org/draft/2020-12/schema#",
223+
"$$schema" : "https://json-schema.org/draft/2020-12/schema",
224224
"$$defs" : {
225225
"Test" : {
226226
"title" : "Test",
@@ -259,7 +259,7 @@ class TapirSchemaToJsonSchemaTest extends AnyFlatSpec with Matchers with OptionV
259259

260260
// then
261261
result.asJson shouldBe json"""{
262-
"$$schema" : "http://json-schema.org/draft/2020-12/schema#",
262+
"$$schema" : "https://json-schema.org/draft/2020-12/schema",
263263
"$$ref" : "#/$$defs/Model",
264264
"$$defs" : {
265265
"Model" : {

0 commit comments

Comments
 (0)