0
class Patient(EndpointsModel): 
    user = EndpointsUserProperty(required=True, raise_unauthorized=True) 
    date_of_birth = EndpointsDateProperty() 
    age = ndb.IntegerProperty() 

    def calculate_age(self): 
     today = date.today() 
     birthday = self.date_of_birth 
     self.age = today.year - birthday.year - ((today.month, today.day) < (birthday.month , birthday.day)) 

    def _pre_put_hook(self): 
     if self.date_of_birth: 
      self.calculate_age() 

.... 
api_root = endpoints.api(name='ffsapi', version='vGDL', 
        description='API for whole app') 


@api_root.api_class(resource_name="patient") 
class PatientApi(remote.Service): 

    @Patient.method(
        request_fields=('name', 'date_of_birth'), 
        name='insert', 
        path='patient', 
        http_method='POST') 
    def insert_patient(self,patient): 
     if patient.date_of_birth: # TODO find a better way 
      if patient.date_of_birth.year <1900: 
       raise endpoints.BadRequestException('date <= 1900') 
     patient.put() 
     return patient 

    @Patient.query_method(user_required=True, 
          query_fields=['name'], 
          name='query', 
          path='patient') 
    def query_patient(self,query): 
     return query 
.... 
application = endpoints.api_server([api_root], restricted=False) 

これは私がendpointscfg.pyを実行すると、ProtoRPCサービスではないことを示すファイルです。私はアプリケーション、api_root、ffsapiを試しました。このコードは、うまく動作するライブラリをコンパイルすることはできません。すなわち、この場合にクラウドエンドポイントをコンパイルするためのライブラリを入手する

application: ******(im just hiding it) 
version: 1 
runtime: python27 
api_version: 1 
threadsafe: yes 

handlers: 
- url: /favicon\.ico 
    static_files: favicon.ico 
    upload: favicon\.ico 

- url: .* 
    script: main.application 

# Endpoints handler 
- url: /_ah/spi/.* 
    script: main.application 


libraries: 
- name: webapp2 
    version: "2.5.2" 
# Needed for endpoints/users_id_token.py. 
- name: pycrypto 
    version: "2.6" 
- name: endpoints 
    version: 1.0 

答えて

0

を助けている場合、あなたが唯一のクラスでAPIを実装しているので、ここで

は、YAMLファイルである、あなたは @endpoints.apiデコレータで PatientApiクラスを飾るの代わりに、別途 endpoints.api()を呼び出す必要がありますその結果を変数に代入する。その後、あなたとAPIサーバーを作成したい:

最後に

application = endpoints.api_server([PatientApi], restricted=False)

、endpointscfg.pyを使用してオープンAPI仕様を生成するために、あなたは(あなたのソースファイルがmain.pyと呼ばれていると仮定)main.PatientApiを渡したいです。

関連する問題