Coder Social home page Coder Social logo

Comments (5)

kemingy avatar kemingy commented on June 11, 2024

It's generated by

spectree/spectree/utils.py

Lines 235 to 244 in 78edc00

def get_model_key(model: ModelType) -> str:
"""
generate model name suffixed by short hashed path (instead of its path to
avoid code-structure leaking)
:param model: `pydantic.BaseModel` query, json, headers or cookies from
request or response
"""
return f"{model.__name__}.{hash_module_path(module_path=model.__module__)}"

The purpose is to avoid the same class name defined in different files.

For now, there is no elegant way to disable it. You can patch this function. Or you may strip the suffix. Depends on your requirements.

from spectree.

AndreasBBS avatar AndreasBBS commented on June 11, 2024

I understand I can fork but I was trying to avoid having to do that. I understand the goal of avoiding having the same class defined in different files.

My use case is that I'm using tools on my API clients to convert the openapi component schemes into types/classes (for example: openapi-typescript). So is it your opinion that this tools should remove the prefix when naming the classes? I'm not sure this prefixing behavior is something defined in the OpenAPI specification so it might not be fair to expect libraries that consume OpenAPI specifications to be able to handle it.

Thanks for the quick reply. I really appreciate that!

from spectree.

kemingy avatar kemingy commented on June 11, 2024

I see your points. I think there is no spec for this.

One possible way to make it easier is moving the related functions to the BasePlugin static methods. So people can inherit and override part of the methods. We can do this step by step. If you're interested in this, you can refactor this get_model_key function.

Similar to #297 (comment)

from spectree.

AndreasBBS avatar AndreasBBS commented on June 11, 2024

I've been looking at the code to try to implement this refactor but I found some issues with moving it to BasePlugin static methods.

In response.py I don't seem to have access to the current plugin/backend like I do in the Spectree class:

model_name = get_model_key(model=model)

Any suggestion to what to do here?

from spectree.

AndreasBBS avatar AndreasBBS commented on June 11, 2024

I've been looking at the code to try to implement this refactor but I found some issues with moving it to BasePlugin static methods.

In response.py I don't seem to have access to the current plugin/backend like I do in the Spectree class:

model_name = get_model_key(model=model)

Any suggestion to what to do here?

This is only used in tests as far as I can tell so I'll go ahead and do the refactor and we can keep discussing how we can refactor the tests.

from spectree.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.