-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OpenAPI: support sibling values for reference schemas #1020
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,19 @@ trait JsonSchemas extends algebra.JsonSchemas with TuplesSchemas { | |
val docs: DocumentedJsonSchema | ||
) | ||
|
||
class RecordReference[A]( | ||
val name: String, | ||
referencedRecord: Record[A] | ||
) extends Record[A](referencedRecord.ujsonSchema, referencedRecord.docs.withName(name)) { | ||
def withName(name: String) = new RecordReference(name, referencedRecord) | ||
|
||
def withExample(example: => ujson.Value): RecordReference[A] = | ||
new RecordReference( | ||
name, | ||
new Record(referencedRecord.ujsonSchema, referencedRecord.docs.withExample(example)) | ||
) | ||
} | ||
|
||
class Record[A]( | ||
override val ujsonSchema: ujsonSchemas.Record[A], | ||
override val docs: DocumentedRecord | ||
|
@@ -399,7 +412,8 @@ trait JsonSchemas extends algebra.JsonSchemas with TuplesSchemas { | |
} | ||
|
||
def namedRecord[A](schema: Record[A], name: String): Record[A] = | ||
new Record(schema.ujsonSchema, schema.docs.withName(name)) | ||
new RecordReference(name, schema) | ||
//new Record(schema.ujsonSchema, schema.docs.withName(name)) | ||
|
||
def namedTagged[A](schema: Tagged[A], name: String): Tagged[A] = | ||
new Tagged(schema.ujsonSchema, schema.docs.withName(name)) | ||
|
@@ -539,10 +553,16 @@ trait JsonSchemas extends algebra.JsonSchemas with TuplesSchemas { | |
case s: LazySchema => LazySchema(s.name, updatedDocs(s.value)) | ||
case s: OneOf => s.copy(example = Some(exampleJson)) | ||
} | ||
new JsonSchema( | ||
schema.ujsonSchema, | ||
updatedDocs(schema.docs) | ||
) | ||
schema match { | ||
case s: RecordReference[A] => | ||
println(s"RECORDREFERENCE ${s.name}") | ||
s.withName(s.name + "$").withExample(exampleJson) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a clever idea, but I'm not sure it'll actually work unless the name mangling is made more complicated. Consider the case where the same |
||
case _ => | ||
new JsonSchema( | ||
schema.ujsonSchema, | ||
updatedDocs(schema.docs) | ||
) | ||
} | ||
} | ||
|
||
def withTitleRecord[A]( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting - I was expecting to see a subclass like this on
DocumentedRecord
, notRecord
.Should it ever be possible to have a
RecordReference
inside of aRecordReference
? Eg.RecordReference("foo", RecordReference("bar", RecordReference("baz", ...)))
? I see some effort here to avoid that case, but I can't tell yet if that is an invariant.