Skip to content

How to read from string? #362

Open
Open

Description

@luckydonald

I couldn't find a way to read from a string, without spamming a temporary file.

from openapi_spec_validator import validate

schema_text = """{"openapi": "3.0.0"}"""

schema: Schema = ???(schema_text)

validate(schema)

Activity

  1. p1c2u commented on Jun 26, 2024

    @p1c2u
    Collaborator

    echo "string" | openapi-spec-validator -

  2. luckydonald commented on Jun 26, 2024

    @luckydonald
    Author

    Apologies, I mean from within python.

    there's read_from_filename, read_from_stdin, but no read_from_str.

  3. p1c2u commented on Jul 2, 2024

    @p1c2u
    Collaborator

    just use json.loads?

  4. kurtmckee commented on Jun 26, 2025

    @kurtmckee
    Contributor

    @luckydonald Code similar to this may do what you want.

    import json
    import pathlib
    
    from openapi_spec_validator import validate
    
    schema = json.loads(pathlib.Path("your-file.json").read_text())
    
    validate(schema)

    @p1c2u I recommend closing this issue. It's had no follow-up in the past year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions