Skip to content

Conversation

@buildpeak
Copy link
Contributor

This is a very simple version of OpenAPI spec just for internal use. At least the developer can use the Swagger page to do some RESTful tests.

@bauerji
Copy link
Collaborator

bauerji commented Sep 28, 2021

Hi,
Thank you for contribution. I am trying to access /docs/ endpoint on both example applications. For example_app.app I am getting empty html response (20 status code). example_app gives me 404 for /docs/. Am I doing something wrong? I thought the example apps should run out of the box.
Jirka

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@buildpeak
Copy link
Contributor Author

buildpeak commented Sep 28, 2021 via email

@bauerji
Copy link
Collaborator

bauerji commented Oct 3, 2021

It seems to work fine now. Except for path parameters. I could not find a way how to specify url path parameters while trying out the API through swagger UI. Would it be a simple fix or should we release it without it?

@buildpeak
Copy link
Contributor Author

buildpeak commented Oct 3, 2021 via email

@bauerji
Copy link
Collaborator

bauerji commented Oct 28, 2021

The problem I was mentioning was in the swagger UI. You have the option to "Try it out" - call the API from UI. I wasn't able to specify the URL path parameters in the UI.

When I am trying it now, I am only getting the empty page when trying to display docs in the example app. I don't know what I am doing wrong

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@bauerji
Copy link
Collaborator

bauerji commented Jul 31, 2022

Hey @buildpeak, I am sorry for such a late response. I've rebased your branch onto current master and I'm getting ImportError: cannot import name 'parse_rule' from 'werkzeug.routing' error. Apparently werkzeug marked the parse_rule method as internal in the latest release.

@The-Podsiadly
Copy link

The-Podsiadly commented Aug 12, 2022

@bauerji @buildpeak I found a workaround. Not the prettiest, but it works apparently according to flask-restx in this PR #463. Let me know if you'd like me to add it this PR.

import re

RE_PARSE_RULE = re.compile(
    r"""
    (?P<static>[^<]*)                           # static rule data
    <
    (?:
        (?P<converter>[a-zA-Z_][a-zA-Z0-9_]*)   # converter name
        (?:\((?P<args>.*?)\))?                  # converter arguments
        \:                                      # variable delimiter
    )?
    (?P<variable>[a-zA-Z_][a-zA-Z0-9_]*)        # variable name
    >
    """,
    re.VERBOSE,
)

def parse_rule(rule):
    """
    Parse a rule and return it as generator. Each iteration yields tuples in the form
    ``(converter, arguments, variable)``. If the converter is `None` it's a static url part, otherwise it's a dynamic
    one.
    Note: This originally lived in werkzeug.routing.parse_rule until it was removed in werkzeug 2.2.0.
    """
    pos = 0
    end = len(rule)
    do_match = RE_PARSE_RULE.match
    used_names = set()
    while pos < end:
        m = do_match(rule, pos)
        if m is None:
            break
        data = m.groupdict()
        if data["static"]:
            yield None, None, data["static"]
        variable = data["variable"]
        converter = data["converter"] or "default"
        if variable in used_names:
            raise ValueError(f"variable name {variable!r} used twice.")
        used_names.add(variable)
        yield converter, data["args"] or None, variable
        pos = m.end()
    if pos < end:
        remaining = rule[pos:]
        if ">" in remaining or "<" in remaining:
            raise ValueError(f"malformed url rule: {rule!r}")
        yield None, None, remaining

@buildpeak buildpeak closed this by deleting the head repository May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants