openapi-core icon indicating copy to clipboard operation
openapi-core copied to clipboard

Is there any provision to pickle spec

Open jugaadi opened this issue 5 years ago • 4 comments

jugaadi avatar Apr 11 '20 13:04 jugaadi

Hi @jugaadi

Can you provide more details on the topic. Which kind of pickle spec provision in openapi-core you looking for?

If you need to support serializing / deserializng Python objects via something like,

components:
  schemas:
    PickleData:
      type: "string"
      format: "pickle"

it in theory possible by providing custom formatter to request / response validator.

But it may lead into a problems if your OpenAPI schema will be shared with other services, which don't know about given pickle format.

With that in mind, I'd suggest you to do pickle/unpickle by yourself and use binary strings for those data,

components:
  schemas:
    BinaryData:
      type: "string"
      format: "binary"

More about media types from OpenAPI docs

playpauseandstop avatar Apr 13 '20 14:04 playpauseandstop

Thanks @playpauseandstop for the response. I tried pickle'ing the result of openapi_core.create_spec() without any success.

My primary motive is to pickle the entire spec to reduce the time taken to parse the openapi spec(json).

jugaadi avatar Apr 13 '20 16:04 jugaadi

Ouch @jugaadi, I've thought about completely different thing 😄


Not sure about your implementation details, but what about instantiating spec once at app startup and then reuse that instance at runtime?

playpauseandstop avatar Apr 13 '20 16:04 playpauseandstop

Not sure about your implementation details, but what about instantiating spec once at app startup and then reuse that instance at runtime?

That's how we are currently handling it.

jugaadi avatar Apr 13 '20 18:04 jugaadi