
    =!g{                         d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZmZ d dlmZ d	d
lmZ d	dlmZ d	dlmZmZ  G d de          ZdS )    N)get_user_model)ImproperlyConfigured)BaseCommand)import_string)api_settings)APIRequestFactoryforce_authenticate)APIView   )openapi)swagger_settings)OpenAPICodecJsonOpenAPICodecYamlc                   8    e Zd ZdZd Zd Zd	dZd Zd Zd Z	dS )
Commandz8Write the Swagger schema to disk in JSON or YAML format.c           	      
   |                     ddddt          d           |                     ddd	d
d           |                     ddddddgt          d           |                     ddddt          d           |                     dddd	d
d           |                     dd t          d!"           |                     d#d$d%&           |                     d'd(d	d
d)           |                     d*d+d,dd-.           d S )/Noutput_filezoutput-file?-z>Output path for generated swagger document, or "-" for stdout.)metavarnargsdefaulttypehelpz-oz--overwriteF
store_truezfOverwrite the output file if it already exists. Default behavior is to stop if the output file exists.)r   actionr   z-fz--formatformat jsonyamlz_Output format. If not given, it is guessed from the output file extension and defaults to json.)destr   choicesr   r   z-uz--urlapi_urlzMBase API URL - sets the host and scheme attributes of the generated document.)r!   r   r   r   z-mz--mock-requestmockzUse a mock request when generating the swagger schema. This is useful if your views or serializers depend on context from a request in order to function.)r!   r   r   r   z--api-versionapi_versionzFVersion to use to generate schema. This option implies --mock-request.)r!   r   r   z--useruserzbUsername of an existing user to use for mocked authentication. This option implies --mock-request.)r!   r   z-pz	--privatea  Hides endpoints not accessible to the target user. If --user is not given, only shows endpoints that are accessible to unauthenticated users.
This has the same effect as passing public=False to get_schema_view() or OpenAPISchemaGenerator.get_schema().
This option implies --mock-request.z-gz--generator-classgenerator_class_namezZImport string pointing to an OpenAPISchemaGenerator subclass to use for schema generation.)r!   r   r   )add_argumentstr)selfparsers     h/var/www/html/nourish/venv/lib/python3.11/site-packages/drf_yasg/management/commands/generate_swagger.pyadd_argumentszCommand.add_arguments   s   =Q 	 	
 	
 	
 	-,J 	 	
 	
 	
 	*8 0r	 	 	
 	
 	
 	'	`	 	 	
 	
 	
 	",J 	 	
 	
 	
 	-Y 	 	
 	
 	

 	6u 	 	
 	
 	
 	+,7 	 	
 	
 	
 	%,Bm 	 	
 	
 	
 	
 	
    c                 |   |dk    rPt          g d          }|                    |                              d          }|                    |           d S |dk    rOt	          g           }|                    |                              d          }|                    |           d S t          d|z            )Nr   T)
validatorsprettyzutf-8r    )r0   zunknown format %s)r   encodedecodewriter   
ValueError)r*   schemastreamr   codecswagger_jsonswagger_yamls          r,   write_schemazCommand.write_schemaL   s    V$4@@@E <<//66w??LLL&&&&&v$333E <<//66w??LLL&&&&&069:::r.   Nc                     t                      }|                    |dz   |z             }|t          ||           t                                          |          }|S )Nz	/swagger.)r&   )r   getr	   r
   initialize_request)r*   urlr   r&   factoryrequests         r,   get_mock_requestzCommand.get_mock_requestY   s]    #%%++cK/&899wT2222))..w77r.   c                 X    t           j        }|rt          |          } ||||          S )N)infoversionr?   )r   DEFAULT_GENERATOR_CLASSr   )r*   r'   api_infor%   r#   generator_classs         r,   get_schema_generatorzCommand.get_schema_generatorb   sC    *B 	B+,@AAO
 
 
 	
r.   c                 0    |                     ||          S )N)rA   public)
get_schema)r*   	generatorrA   rK   s       r,   rL   zCommand.get_schemam   s    ##GF#CCCr.   c
                 z   t          j        t           j                   t          t          dd           }t          |t          j                  st          d          |s)t          j
                            |          d         dv rd}|pd}|pt          j        }|r1 t                      j        j        di t                      j        |i}|p	|p|d up|d u}|r|st          d          d }|r|                     |||          }|pt$          j        }|r	|r||_        |                     |	|||          }|                     |||           }|dk    r|                     || j        |           d S |rd	nd
}t3          ||          5 }|                     |||           d d d            d S # 1 swxY w Y   d S )NDEFAULT_INFOzgsettings.SWAGGER_SETTINGS["DEFAULT_INFO"] should be an import string pointing to an openapi.Info object   )z.ymlz.yamlr    r   zh--mock-request requires an API url; either provide the --url argument or set the DEFAULT_API_URL settingr   wx )loggingdisableWARNINGgetattrr   
isinstancer   Infor   ospathsplitextDEFAULT_API_URLr   objectsr=   USERNAME_FIELDrB   r   DEFAULT_VERSIONrE   rI   rL   r;   stdoutopen)r*   r   	overwriter   r#   r$   r%   r&   privater'   argskwargsrD   rA   rM   r6   flagsr7   s                     r,   handlezCommand.handlep   sZ    	((('>>$-- 	&C  
  	 w,,Q/3DDD!6=-= 	[ 0>##+/ZZ>3C3C3RTX2YZZDQwQ4t#3QD9P 	 	&H  
  	C++GVTBBG!A\%A 	*{ 	*)GO--.BD+W^__	G[AA#fdk6:::::$-CC#Ek5)) :V!!&&&999: : : : : : : : : : : : : : : : : :s   F00F47F4)N)
__name__
__module____qualname__r   r-   r;   rB   rI   rL   rh   rS   r.   r,   r   r      s|        ED6
 6
 6
p; ; ;   	
 	
 	
D D D/: /: /: /: /:r.   r   )rT   rZ   django.contrib.authr   django.core.exceptionsr   django.core.management.baser   django.utils.module_loadingr   rest_framework.settingsr   rest_framework.testr   r	   rest_framework.viewsr
   r   r   app_settingsr   codecsr   r   r   rS   r.   r,   <module>ru      s    				 . . . . . . 7 7 7 7 7 7 3 3 3 3 3 3 5 5 5 5 5 5 0 0 0 0 0 0 E E E E E E E E ( ( ( ( ( (       , , , , , , 8 8 8 8 8 8 8 8N: N: N: N: N:k N: N: N: N: N:r.   