
    Tiz                     `    S r SSKrSSKrSSKrSSKJr  S rS rS rS r	S
S jr
S\SS4S	 jrg)z
What's the big idea?

An endpoint that traverses all restful endpoints producing a swagger 2.0 schema
If a swagger yaml description is found in the docstrings for an endpoint
we add the endpoint to swagger specification output

    N)defaultdictc                 8    U (       a  U R                  SS5      $ U $ )N
z<br/>)replace)comments    _/var/www/html/backend/Backoffice_Marketplace/venv/lib/python3.13/site-packages/flask_swagger.py	_sanitizer	      s    -47??4)A'A    c                     SnU R                  5        Hg  nX;   d  M
  UR                  5       R                  S5      n[        U5      S:X  d  M:  US   R                  5       U:X  d  MS  US   R                  5       n  U$    U$ )zZ
Finds a line in <full_doc> like

    <from_file_keyword> <colon> <path>

and return path
N:   r      )
splitlinesstripsplitlen)full_docfrom_file_keywordpathlinepartss        r   _find_from_filer      su     D##%$JJL&&s+E5zQ58>>#37H#HQx~~'K & Kr
   c                 v    S n[        U 5       nUR                  5       nS S S 5        U$ ! , (       d  f       U$ = fN)openread)r   docfs      r   _doc_from_filer   (   s2    
C	dqffh 
J 
Js   )
8c                    Su  p4n[         R                  " U 5      nU(       a  Ub&  [        Xb5      nU(       a  [        U5      nU(       a  UnUR	                  S5      n	U	S:w  a`  U" US U	 5      nXiS-   S  R	                  S5      n
U
S:w  a+  U" XiS-   X-    5      n[
        R                  " XiU
-   S  5      nOU" XiS-   S  5      nOUnX4U4$ )N)NNNr   r   z---)inspectgetdocr   r   findyaml	full_load)objprocess_docr   
first_lineother_linesswagr   	from_filefull_doc_from_file	line_feedyaml_seps              r   _parse_docstringr0   /   s    $4!JT~~c"H('DI%3I%>"%1HMM$'	?$Xjy%9:J!-2259H2~)(Q;y?Q*RS~~h/A/B&CD)(Q;<*@A!JD((r
   c                   ^ U4S jnTc  Sm[        5       nU b  U  H  nUR                  S5      nUb  UR                  S5      nUbC  UR                  U5        SSR                  U5      0nTS:X  a  XtS'   OUR	                  U5        US	 UR                  S5      nUb   U[        UR                  5       TS-   5      -  nX2" U5      -  nX2" U5      -  nM     U$ )	z
Since we couldn't be bothered to register models elsewhere
our definitions need to be extracted from the parameters.
We require an 'id' field for the schema to be correctly
added to the definitions list.
c                 f   > / nU R                  S5      nUb  SU;   a  U[        U/TS-   5      -  nU$ )Nitemsschemar   )get_extract_definitions)sourceretr3   levels      r   _extract_array_defs1_extract_definitions.<locals>._extract_array_defsO   sB     

7#U!2'q99C
r
   r   r4   idz$refz#/definitions/{}
propertiesr   )listr5   appendformatupdater6   values)	alistr9   r:   defsitemr4   	schema_idrefr=   s	    `       r   r6   r6   G   s     }6DDXXh'F!"JJt,	(KK'!#5#<#<Y#GHC
 z),XC( N $ZZ5
)01B1B1DeAgNND+F33'--D3 6 Kr
   c           	         SSSS.S.n[        [        5      n[        [        5      nUbk  UR                  U5        UR                  S0 5      R	                  5        H	  u  pXU'   M     UR                  S0 5      R	                  5        H	  u  pXU'   M     XeS'   XuS'   S	S
1n
/ SQnU R
                  R                  5        GH  nU(       a  UR                  S[        U5       U:w  a  M)  U R                  UR                     n[        5       nUR                  R                  U
5       Hx  nUR                  5       n[        US5      (       aP  U[        S UR                  5      ;   a5  [        UR                   U5      (       a  [#        UR                   U5      X'   Mt  XU'   Mz     [        5       nUR	                  5        GH6  u  nn[%        UUU5      u  nnnUc  M  UR                  S/ 5      n['        U5      nUR                  S/ 5      nU['        U5      -  nUR                  S0 5      nUR	                  5        VVs0 s H  u  nn[)        U5      U_M     nnnUb  U['        UR+                  5       5      -   nU H-  nUR-                  S5      nUc  M  UU   R                  U5        M/     [        UUUS9n[        U5      S:  a  UUS'   U H  nUU;   d  M  UR                  U5      UU'   M!     UUU'   GM9     [        U5      (       d  GMK  [)        U5      n[.        R0                  " SU5       H  nUR3                  US   SUS   -  5      nM      Xl   R                  U5        GM     U$ s  snnf )an  
   Call this from an @app.route method like this
   @app.route('/spec.json')
   def spec():
      return jsonify(swagger(app))

   We go through all endpoints of the app searching for swagger endpoints
   We provide the minimum required data according to swagger specs
   Callers can and should add and override at will

   Arguments:
   app -- the flask app to inspect

   Keyword arguments:
   process_doc -- text sanitization method, the default simply replaces 
with <br>
   from_file_keyword -- how to specify a file to load doc from
   template -- The spec to start with and update as flask-swagger finds paths.
   z2.0z0.0.0zCool product name)versiontitle)swaggerinfoNpathsdefinitionsHEADOPTIONS)tagsconsumesproducesschemessecurity
deprecatedoperationIdexternalDocsmethodsc                 "    U R                  5       $ r   )lower)ms    r   <lambda>swagger.<locals>.<lambda>   s
    aggir
   
parameters	responsesr<   )summarydescriptionr`   r   z(<([^<>]*:)?([^<>]*)>)z{%s}r   )r   dictrA   r5   r3   url_map
iter_rulesruler   view_functionsendpointrY   
differencer[   hasattrmap
view_classgetattrr0   r6   strrB   poprefindallr   )appprefixr(   r   templateoutputrM   rN   kvignore_verbsoptional_fieldsrf   rh   rY   verb
operationsmethodra   rb   r+   rD   paramsr`   keyvalue
definitiondef_id	operationargs                                 r   rK   rK   |   sB   * (
F Ed#KhJJw+113DA!H 4JJ}b1779DAN :7O'=I&LDO &&(diiV-7%%dmm4&LL++L9D::<Dx++$79I9I JJ 3 3T:: '(;(;T B ( : V
#MMOLD&)9&+:K*M&G[$xxr2+D1,3,V44 HH["5	 '0oo&7&7
U HeO&7   ("6y7G7G7I"JJD"&J'^^D1F)#F+22:> #' !# +'	 v;?.4Il+*Cd{)-#	# + $-
4 ? ,B z??t9Dzz":DA||CFFSVO< BKz*g )h M;s   ;M(
r   )__doc__r"   r%   rp   collectionsr   r	   r   r   r0   r6   rK    r
   r   <module>r      sE      	 #B()02j )"T`r
   