Skip to content

Add normal function to generate openapi document - #24

Closed
test-codeop wants to merge 10 commits into
uncover-agentfrom
uncover-agent-2426527792
Closed

test-codeop wants to merge 10 commits into
uncover-agentfrom
uncover-agent-2426527792

Conversation

@test-codeop

Copy link
Copy Markdown
Collaborator

Overview

This pull request aims to add a normal public function to generate the OpenAPI document content which can be used programmatically by the external implementations that wraps pygeoapi as a library. It keeps backward compatibility with the click function.

Example:

    try:
        # override pygeoapi os variables
        os.environ["PYGEOAPI_CONFIG"] = cfg.PYGEOAPI_CONFIG
        os.environ["PYGEOAPI_OPENAPI"] = cfg.PYGEOAPI_OPENAPI

        from pygeoapi.starlette_app import app as pygeoapi_app
        from pygeoapi.provider.base import ProviderConnectionError
        from pygeoapi.openapi import get_oas, generate_openapi_document

        pygeoapi_conf = Path.cwd() / os.environ["PYGEOAPI_CONFIG"]
        pygeoapi_oapi = Path.cwd() / os.environ["PYGEOAPI_OPENAPI"]
        with pygeoapi_oapi.open(mode="w") as oapi_file:
                s = generate_openapi_document(pygeoapi_conf)
                oapi = get_oas(s)
                oapi_file.write(oapi)

    except ProviderConnectionError as e:
        loguru.logger.error(e)
        raise e
    except FileNotFoundError:
        loguru.logger.error(
            "Please configure pygeoapi settings in .env properly"
        )
        raise

Related Issue / Discussion

Additional Information

Contributions and Licensing

(as per https://github.com/geopython/pygeoapi/blob/master/CONTRIBUTING.md#contributions-and-licensing)

  • I'd like to contribute [feature X|bugfix Y|docs|something else] to pygeoapi. I confirm that my contributions to pygeoapi will be compatible with the pygeoapi license guidelines at the time of contribution.

  • I have already previously agreed to the pygeoapi Contributions and Licensing Guidelines

  • Original PR: Add normal function to generate openapi document geopython/pygeoapi#1080

  • Reproduced automatically by test_create_prs.py to exercise the Detect AI workflow.

@doublebyte1
doublebyte1 deleted the uncover-agent-2426527792 branch October 20, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants