line / armeria

Your go-to microservice framework for any situation, from the creator of Netty et al. You can build any type of microservice leveraging your favorite technologies, including gRPC, Thrift, Kotlin, Retrofit, Reactive Streams, Spring Boot and Dropwizard.
https://armeria.dev
Apache License 2.0
4.83k stars 921 forks source link

Support JSONSchema for Thrift TText protocol #4601

Open Dogacel opened 1 year ago

Dogacel commented 1 year ago

Motivation:

Improve JSON Schema support for Thrift TText protocol to ramp up DocService.

Parent PR:

Requirements:

Note: It seems like typedefs are unresolved types in ServiceSpecification

so we first need to fix that.

For enum support, the generated schema can look like this:

    "test_enum" : {
      "type": ["string", "number"],
      "description" : "",
      "enum" : [ "ZERO", "ONE", "TWO", 0, 1, 2 ],
      "additionalProperties" : true
    },

Testing

Compared schemas for

We can compare using HBase and Cassandra but I got kinda lazy and my Thrift knowledge is very low.

Here is the current status of the schema as of 31.12.2022:

minwoox commented 1 year ago

Typedef support

I completely forgot about this. 😓 Let me handle it.

Numerated enum support

Did you menat TypedefedEnum?

Dogacel commented 1 year ago

Did you menat TypedefedEnum?

No, I thought you can give numbers as enums (e.g. 1, 2) but JSON schema currently only accepts names (string) for enums.

minwoox commented 1 year ago

Oops, I think I don't get it. 😅

you can give numbers as enums

Do you mean specifying numbers as enums when sending a request? But, couldn't we get the information of enums when creating the JSON schema regardless of the Numerated enum?

Dogacel commented 1 year ago

Oops, I think I don't get it. 😅

you can give numbers as enums

Do you mean specifying numbers as enums when sending a request? But, couldn't we get the information of enums when creating the JSON schema regardless of the Numerated enum?

Yeah, we do have more information (possible enum values are autocompleted). I just wanted to fully support existing features but if you think nobody uses numbers as enums while sending thrift requests then it should be fine.

minwoox commented 1 year ago

Ah ah, so you mean we can create the JSON schema with the information but we cannot support auto-completion when sending a request using numbers? Is that correct? 😄 Then, probably we can specify all the values we support? 🤔

{
  "enum": ["red", "amber", "green", 1, 2, 3]
}
Dogacel commented 1 year ago

Ah ah, so you mean we can create the JSON schema with the information but we cannot support auto-completion when sending a request using numbers? Is that correct? 😄 Then, probably we can specify all the values we support? 🤔

{
  "enum": ["red", "amber", "green", 1, 2, 3]
}

Updated ticket description.

minwoox commented 1 year ago

Typedef support (currently they are only object).

This will be supported by https://github.com/line/armeria/pull/4628